Reputation: 1771
$('#password').val().indexOf(/[a-z]/) != -1)
Does this work? if so is there something wrong with it because its not working.
Upvotes: 0
Views: 321
Reputation: 15433
No this will not work because you have to use match()
function for that.
I also recommend that if you want only numbers then you should try to validate only numbers.
Do not allow anything else except number.
if( $('#password').val().match(/[0-9]+/) ){
// Contains only numbers from 0-9
}
Upvotes: 0
Reputation: 3333
Do your check like the following because you want to work with an object supporting regular expression syntax:
var valContainsLetter = /[a-z]/i.test($('#password').val())
The i
flag is to support lower and upper case letters by the way.
Upvotes: 1