java脚本中的百分比验证...帮帮我 [英] percentage validation in java script...help me know
本文介绍了java脚本中的百分比验证...帮帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我输入的数字超过2位,则不应接受,而textbox肯定包含%符号...例如:99%...应采用此格式
解决方案
尝试阅读本文,
http:// www.w3schools.com/js/js_form_validation.asp [ ^ ]
< html >
< head >
< meta charset = UTF-8 >
< title < span class =code-keyword>> ssn Checker < / title < span class =code-keyword>>
< script type = text / javascript >
var Pattern = (\d +(\.\d +)%);
function checkPercentage(Percentage){
if (Pattern。 test(Percentage)){
alert( VALID Percentage);
} else {
alert( 无效百分比);
}
}
< / script >
< / meta > < / head >
< 正文 >
< 表单 önsubmit = 返回false; > ;
< 输入 类型 = text name = 百分比 size = 20 >
< input 类型 = 按钮 value = 检查 >
onclick =checkPercentage(this.form.Percentage.value);> ;
< / input > < / input > < / form >
< / body >
< / html >
第二种方式,您可以使用Dotnet验证控件(正则表达式)。在属性中定义正则表达式并根据您的要求自定义它。
查询的正则表达式:
(\d +( \。\ d +)?%)
^ 0 *(100 \\\ 00 | [0-9]?[0-9] \。[0-9] {2} )%
if i enter more than 2 digits it should not accept and textbox should surely contains % symbol...example:99%...should be in this format
解决方案
Try reading over this,
http://www.w3schools.com/js/js_form_validation.asp[^]
<html> <head> <meta charset="UTF-8"> <title>ssn Checker</title> <script type="text/javascript"> var Pattern= (\d+(\.\d+)?%); function checkPercentage(Percentage){ if (Pattern.test(Percentage)) { alert("VALID Percentage"); } else { alert("INVALID Percentage"); } } </script> </meta></head> <body> <form önsubmit="return false;"> <input type="text" name="Percentage" size="20"> <input type="button" value="Check"> onclick="checkPercentage(this.form.Percentage.value);"> </input></input></form> </body> </html>
Second way, You can use Dotnet validation control(regular expression). Define your regex expression in the properties and Customize it as per your requirement.
Regular expression for your query:
(\d+(\.\d+)?%)
^0*(100\.00|[0-9]?[0-9]\.[0-9]{2})%
这篇关于java脚本中的百分比验证...帮帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文