In general, I check the string for 2 conditions with a regular schedule. I can not understand what I am doing wrong. You need to check to enter either a string of letters or email.

Tell me why the function gives two values?

function is_valid(login) { if (login.match(/^((([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([az\.]{2,6})) | ([a-z0-9_-]{3,16}))$/gi) != null) { login = login.match(/^((([a-z0-9_\.-]+)@([a-z0-9_\.-]+)\.([az\.]{2,6})) | ([a-z0-9_-]{3,16}))$/gi).join(''); return login; } else { $('#inLogin').css('border', 'red 1px solid'); error = 2; return; } console.log(login); console.log(error); } 
  • one
    At least clean around | spaces - Visman
  • @Visman Thank you))) helped) - dpi
  • @visman can be a little explanation why the spaces around | caused this behavior? Thank. - excellproj
  • one
    @excellproj, because the space is also a symbol and it turned out: for emal, there must be a space at the end, and for the login - a mandatory space at the beginning. Flag Ignore whitespace in relys js not to ignore spaces. - Visman
  • @visman thank you very much. You should get an answer) - excellproj

0