In the past, I used javascript to write a verification text box that can only input decimal places (two decimal places need to be retained). Remember that it is mainly implemented by judging eventkey or evencode, the text box must be added for the projects that have been replaced by others. Only numbers and letters can be entered, and both the backend and foreground verification are allowed. In order to minimize code changes, JavaScript is used for verification.
The Code is as follows:
Copy to ClipboardReference: [www.bkjia.com] <script type = "text/javascript">
Var re =/^ [A-Za-z0-9] * $ /;
Var str = '';
Function checknum (obj)
{
If (re. test (obj. value) = false ){
Obj. value = str;
Alert ("only input alpha numeric characters ");
} Else {
Str = obj. value;
}
}
<Input type = "text" name = "txtName" onpropertychange = "checknum (this)">
It seems that regular expression verification is quite simple.