I am trying to validate whether a HTML field is between 11 and 13 characters long.
I have tried using:
if(!phoneCheck.test(phone) || (phone.length !>= 11 && phone.length !<=13))
But this does not seem to work. It just stops all Javascript as if there is an error in it.
How would i go about doing this?
EDIT:
Sorry i shouldve added a further part of the code:
if(!phoneCheck.test(phone) || (phone.length !>= 11 && phone.length !<=13))
{
error = "Please give a valid phone number.";
}
The exclamation mark was added so that if it WAS NOT between those lengths then it would trigger the error
The symbols !>=
and !<=
don't exist. The condition code to check if field is between 11 and 13 characters long is:
(phone.length >= 11 && phone.length <= 13)
OBS:
<=
means "less or equal" and >=
means "bigger or equal".
!
is the logical denial.
For example:
!true
is false
and
!(a>b)
is true when a<=b
EDIT: With your edit, what you want is to deny the entire sentence, so the solution is:
!(phone.length >= 11 && phone.length <= 13)
So your if statement should be:
if(!phoneCheck.test(phone) || !(phone.length >= 11 && phone.length <=13))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.