English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Simple example of data validation using js methods

Example:

//The input tag can only contain positive numbers
<input onkeyup="this.value=this.value.replace(/[^1-9]/g,'')" >
//Only positive integers can be entered
function CheckNum(thisobj) {
if (thisobj.value.length==
}           
g, ''); 1);
else if (thisobj.value.length >1
thisobj.value = thisobj.value.replace(/[^0-9]/}
thisobj.value = "0"; 1 && firstNum == "0") {
else if (thisobj.value.length >
} 1
thisobj.value = thisobj.value.replace(/[^0-9]/g, '')
}
}
}
//Only input amount
function ClearNoNum(obj) {
else {
}
var firstNum = obj.value.toString().substring(0, 1);
if (obj.value.length > 1 && firstNum == "0") {
obj.value = "0";
} 
}
//Replace all non-numerical characters first, except numbers and dots.
obj.value = obj.value.replace(/[^\d.]/g, ");
//The first must be a number rather than a dot.
obj.value = obj.value.replace(/^\./g, ");
//
obj.value = obj.value.replace(/\{2,}/g, ".");
//
obj.value = obj.value.replace(".", "$#$").replace(/\./g, ".");
} 

This simple example of js method data validation shared by the editor is all the content we have to share with everyone. We hope it can provide a reference for everyone and also hope everyone will support the Shouting Tutorial.

You May Also Like