SoFunction
Updated on 2025-04-02

Simple example of js method data verification

Examples are as follows:

//Input tag can only be positive numbers<input onkeyup="=(/[^1-9]/g,'')" >

//Only positive integers can be enteredfunction CheckNum(thisobj) {
if ( == "0") {
} else {           
var firstNum = ().substring(0, 1);
if (==1) {
 = (/[^0-9]/g, '');
}else if ( > 1 && firstNum == "0") {
 = "0";
} else if ( > 1) {
 = (/[^0-9]/g, '')
}
}
}
//Only enter amountfunction ClearNoNum(obj) {
if ( == "0") {
} else {
var firstNum = ().substring(0, 1);
if ( > 1 && firstNum == "0") {
 = "0";
} 
}
//Replace all non-digits first, except for the numbers and. = (/[^\d.]/g, "");
//The first one must be guaranteed to be a number instead of. = (/^\./g, "");
//Certificate that only one appears, but no more. = (/\.{2,}/g, ".");
//Please guarantee. It only appears once, but not more than twice = (".", "$#$").replace(/\./g, "").replace("$#$", ".");
} 

The above simple example of data verification of js method is all the content I share with you. I hope you can give you a reference and I hope you can support me more.