JavaScript verification content is a number and a simple instance of length 10
<html><head> <script type="text/javascript"> function valid() { var numVal = document.getElementById("num").value; if(numVal!=undefined&&&numVal!=""){ if(!validateNum(numVal)){ return ; } } else { alert("No value entered!") return ; } alert("The data format is correct, you can submit"); } //Verification must be 10 as a number function validateNum(str) { if(str.length != 10) { alert("Invoice code must be 10 digits"); return false; } else { for(var i=0; i<str.length; i++) { if(str.charAt(i)<'0' || str.charAt(i)>'9') { alert("Invoice code can only be a number"); return false; } } } return true; } </script></head><body><input type="text" name="num" id="num"/><input type="button" value="verification" onclick="valid()" /></body></html>The above javascript verification content is a number and a simple example of the length of 10 is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.