function validateNum(obj) {
//Positive integer (this Cache is used here)
var number = obj.data(validate).number;
//Decimal point (cache is used here)
var decimal = obj.data(validate).decimal;
//Dynamic basic verification regular
eval("var reg = /^[0-9]{0," number "}([.]?[0-9]{0," decimal "})$" "/g;");
var value = obj.val();
var maxnumlen = number decimal 1; //Maximum length 1 (decimal point)
if (!reg.test(obj.val ())) return false;
//The maximum length is equal to the length of the current value and the value does not have "."
if (maxnumlen == value.length && value.indexOf('.') <= 0) {
return false;
}
//Try to get the index of "."
var valueindexof = value.indexOf('.');
if (valueindexof > 0) { // If". "One after the index is empty, then it must be returned to false
if (value.charat (valueINDEXOF 1) ==" ") {
Return false;
}
}
//Split the value to easily determine the content before and after
var valuesplit = value.split('.');
//If the length of the value is greater than the defined positive integer length
if ( value.length > number) {
.
if (maxnumlen - number >= maxnumlen) {
After caching a validate object, just call it.
Definition:
$("#example").data("validate", { number: 2, decimal: 2 });
Call:
validateNum($("#example)) ;