[英]Validate Text Field Length In Between 2 Numbers
I am trying to validate whether a HTML field is between 11 and 13 characters long. 我正在尝试验证HTML字段的长度是否在11到13个字符之间。
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.
它只是停止所有Javascript,就好像它有一个错误。
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: 检查字段长度是否在11到13个字符之间的条件代码是:
(phone.length >= 11 && phone.length <= 13)
OBS: OBS:
<=
means "less or equal" and >=
means "bigger or equal". <=
表示“小于或等于”, >=
表示“大于或等于”。
!
is the logical denial. 是逻辑上的否认。
For example: 例如:
!true
is false
!true
是false
and 和
!(a>b)
is true when a<=b
当
a<=b
时!(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语句应为:
if(!phoneCheck.test(phone) || !(phone.length >= 11 && phone.length <=13))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.