验证Java脚本中的金额 [英] Validation for amount in java script
本文介绍了验证Java脚本中的金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我解决问题
我需要对金额进行验证,以使该数字中的12位数字最大为15位,例如:123456789101.以及一个点号(.)以及该数字后的两位数.
例如:123456789101.00
Can any one help me in solving the problem
I need validation for amount in such a way that it should be maximum of 15 digits in that 12 digits numbers Ex:123456789101. and a dot(.) and after that 2 digits.
EX: 123456789101.00
推荐答案
试试这个例子
Hi,
Try this example
<html>
<head>
<script type="text/javascript">
function demo(){
var amount=document.getElementById('amount').value;
var result=isValidAmount(amount);
if(result==true){
alert("Valid Amount");
}else{
alert("Invalid Amount");
}
}
function isValidAmount(amount){
var regEx=/^\d{1,13}.\d{2}
/; if(amount.search(regEx)==-1){ 返回false; }别的{ 返回true; } } < /script > < /head > < 正文 > < 输入 =" 文本" id >金额" / > < 输入 =" 按钮" 值 测试验证" onclick =" demo();" > < /body > < /html >
/; if(amount.search(regEx)==-1){ return false; }else{ return true; } } </script> </head> <body> <input type="text" id="amount" /> <input type="button" value="Test Validate" onclick="demo();"/> </body> </html>
这篇关于验证Java脚本中的金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文