[英]how to put a validation on html php code
My question is about validation in html. 我的问题是关于html中的验证。 At the moment, if I input 100 or 1000 it will work as intended.
此刻,如果我输入100或1000,它将按预期工作。
This is my html code: 这是我的html代码:
<tr>
<th scope="row" colspan = "1"><font size="5">Number of Guests:</th>
<td colspan = "2"><input type = "text" name = "guest" maxlength = "4" id="guest"
pattern="[0-9]{3,4}" title = "Number of guests must be more than 100 people."></td>
</tr>
My problem is that when I try to input 001 or 000 it still works. 我的问题是,当我尝试输入001或000时,它仍然有效。 How can I counter that problem?
我该如何解决这个问题? Do I have to validate in php?
我必须在php中验证吗? Thank you for any comments or suggestions.
感谢您的任何意见或建议。
试试这将适用于数字
<input type = "number" name = "guest" min = "100" max="1000" id="guest" title = "Number of guests must be more than 100 people.">
使用KótaPéter的想法
pattern="^[1-9][0-9]{2,3}"
Try this pattern: ^(0?[1-9][0-9]{2}|[1-9][0-9]{3})$
尝试以下模式:
^(0?[1-9][0-9]{2}|[1-9][0-9]{3})$
this way you disallow input 0100,001,099,0099
这样您不允许输入
0100,001,099,0099
使用以下代码仅获得所需的值。
<input type = "text" name = "guest" maxlength = "4" id="guest" min="100" max="1000" pattern="^[1-9][0-9]*$" title = "Number of guests must be more than 100 people.">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.