HTML号码字段检查

时间:2017-05-25 04:15:27

标签: php html

在HTML编号字段中,我希望用户输入介于10到20之间,然后是40到50之间的数字...如何在HTML文本字段或数字字段中实现此内容。

4 个答案:

答案 0 :(得分:1)

与在HTML 5中一样,您可以执行此操作



<form action="">
<input type="number" min="10" max="20"/>
<input type="submit"/>
</form>
&#13;
&#13;
&#13;

如果您从数据库获得价值/想要与php值集成,您可以执行以下操作。

<input type="number" min="<?php echo $minVal ?>" max="<?php echo $maxVal ?>"/>

请记住:当您进行验证时,您必须对前端后端进行验证。最小和最大属性不仅限于number类型,您可以将其用于date类型,也可以参考 this

答案 1 :(得分:0)

如果您不想使用javascript或jquery,可以使用 min max 属性

<input type="number" min="10" max="20">
<input type="number" min="40" max="50">

答案 2 :(得分:0)

我不认为单独使用html是可能的。您将不得不使用JavaScript验证,因为这里的条件与html相比很复杂。

答案 3 :(得分:0)

您可以尝试使用html5中的模式:

SELECT `id` FROM `jobs` WHERE `job_type` IN ( 'topemployercheckbox1','topemployercheckbox2') OR `job_category` IN ( 'Contract','Intern') ;

使用javascript检查简单和简短:

<input type="text" name="range" pattern="^(?:\d[10-20]|\d[40-50])$" >
function allownums(a) 
{ 
value1 = a.value;
if( (10<value1==value1<20) || (40<value1==value1<50)) 
alert("vaild") 
else 
alert("invaild") 
} 

如果你只想使用html,你可以使用两个数字字段:

<input type='text' id='numonly' onkeyup='allownums(this)'>