JavaScript form validation can only enter decimals ...
Source: Internet
Author: User
about form validation, it is best to use regular expressions, of course, if the simple do not bother to write regular expressions, in general, use the Internet to search a lot of regular expressions, all kinds of, everything, The following example is a sample of JavaScript validation input decimal values: function Isfunkey (code) { //8--> backspace //--> end // ; home //Notoginseng--> left arrow //--> right arrow //--> delete //112~123--> F1~F12 var Funkeys = [8, N, Panax Notoginseng, 46]; for (var i = 112; I <= 123; i++) { Funkeys.push (i); }&NB Sp for (var i = 0; i < funkeys.length i++) { if (funkeys[i] = = code) { return true; } } retur N false; } function GetChar (k) { if (k >= && k <=) { return String.fromCharCode (k); } if (k >= && k <=) { return String.fromCharCode (k-48); } if (k = = 110 | | K = = 190 | | k== 188) { return "."; } if (k = = 109 | | k = = 189) { return "-"; } if (k = = | | k = = 187) { return "+";nbsp } return "#"; } In short, JavaScript verifies the form, uses the encoded values of each character, and then combines logical judgments, which are not difficult to write.
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.