HTML code:
Copy codeThe Code is as follows:
Enter the price:
<Input type = "text" id = "txtProPrice"/>
<Input type = "button" value = "verify input" id = "btnTest"/>
JS Code:
Copy codeThe Code is as follows: <script src = "jquery. js">
</Script>
<Script type = "text/javascript" language = "javascript">
Function ckProPrice (){
// Determine the product price
Var reg =/(^ [-+]? [1-9] \ d * (\. \ d {1, 2 })? $) | (^ [-+]? [0] {1} (\. \ d {1, 2 })? $ )/;
If ($ ("# txtProPrice"). val () = ""){
Alert ("the product price cannot be blank! ");
Return false;
} Else {
If (! Reg. test ($ ("# txtProPrice"). val ())){
Alert ("the market price must be a legal number (positive number, up to two decimal places )! ");
Return false;
} Else {
Alert ("the input is valid! Yige.org ");
Return true;
}
}
}
$ (Function (){
$ ("# BtnTest"). click (function (){
CkProPrice ();
});
});
</Script>