JS can only enter a number (positive integer, positive, negative, decimal) This is a simple use of JS to verify that you can only enter a number (positive integer, positive, negative, decimal) Oh, if you are considering allowing users to enter numbers can come in and see. Only numeric regular validation
The Validation text box in contains only integers and can be entered, positive and negative integers, and other characters cannot be entered Use this code to solve the problem var flag3 = false; var planallocation = document.getelementsbyname (' planallocation_xx '); Planned allocation var size1 = planallocation.length; var exp =/^ (-?[ 1-9][0-9]*|0) $/; Determines the number of planned entries entered is an exception character for (Var i=0;i<size1;i++) { if (!exp.test (Planallocation[i].value)) { Flag3 = true; break; } }
if (flag3==true) { Alert ("Please input integer, cannot contain special characters"); return false; }
Can only be digital isNaN
<script language= "javascript" type= "Text/javascript" function checknum (obj) { var re =/^-?[ 1-9]* (. d*)? $|^-?d^ (. d*) $/; if (!re.test (obj.value) { if (isNaN (obj.value)) { alert ("illegal numbers"); obj.value= ""; Obj.focus (); return false;} } } </script><input name= "rate" type= "text" onkeyup= "Checknum (This)"/>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.