Tuesday, 10 September 2013

Javascript indexOf or Contains

Javascript indexOf or Contains

I would like to validate a field with the following condition: Password
should not contain any words in the email.
e.g. email: tryemail@yahoo.com
So password must not contain tryemail word.
With this code, I achieve it:
var emailSubstring = email.substr(0, email.indexOf("@"));
if (password.indexOf(emailSubstring) != -1)
{
// do something here //
}
My problem is this: When I enter the word try on the password field, it is
not validating it. Unless I make it tryemail.
Is there any possible way to do it? Thanks in advance!
Note: This is not a password requirements policy issue. I appreciate your
opinion about why should I validate password. My answer would be business
requirements. Thanks!

No comments:

Post a Comment