There is a scenario for entering the amount, this amount needs to be verified and the verification instructions are as follows:
cannot be a space;
cannot be 0;
Cannot be a Chinese character;
cannot be a different character;
cannot be greater than 200;
The only thing you can do is to enter a number between 3~199, and the following OK button will show, otherwise, hide this button.
Html:
<!--amount of Doctor's consultations - <Divclass= "Weui-jiaj-panel"> <Divclass= "Weui-jiaj-money-box dialog js_show"> <Divclass= "Weui-jiaj-money-box-btn"> </Div> <Divclass= "Weui-jiaj-money-box-three"> <Divclass= "Weui-flex__item"> <aID= "Showmoney"href= "javascript:;"class= "Weui-btn weui-btn_mini weui-btn_default">Other</a> </Div> </Div> </Div> </Div> <!--Other Amount - <Divclass= "Weui_dialog_alert"ID= "Showmoneydialog"style= "Display:none;"> <Divclass= "Weui_mask"></Div> <Divclass= "Weui_dialog"> <Divclass= "WEUI_DIALOG_HD"><Strongclass= "Weui_dialog_title">Other amount</Strong></Div> <Divclass= "WEUI_DIALOG_BD"> <Divclass= "Weui-jiaj-dialog-panel"> <Divclass= "Weui-cell"> <Divclass= "WEUI-CELL__BD"> <inputID= "Dialogprice"type= "text"Required Class= "Weui-input"placeholder= "¥10" /> </Div> </Div> </Div> </Div> <Divclass= "Weui_dialog_ft"> <DivID= "Otherpricebtn"class= "Weui_btn_dialog primary">Are you sure</Div> </Div> </Div> </Div>
Js:
<script>//Set Other Amounts varDoctorprices = [{ "Doctorprice": "5" }, { "Doctorprice": "10" }, { "Doctorprice": "15" }, { "Doctorprice": "20" }, { "Doctorprice": "30" }, { "Doctorprice": "60" }]; varUserId = $.cookie (' Doctorid '); $(function() {selectedprice (); }); varpage = $ ('. Page ');//top-level div varpanel = page.find (' Weui-jiaj-panel '); functionSelectedprice () {var$titleHtml = "; for(varA = 0; A < Doctorprices.length; a++) { varPricename =Doctorprices[a].doctorprice; //Dot week weui_btn_dialog hidden$titleHtml + = ' <button class= "price_btn weui-btn weui-btn_mini weui-btn_warn" ' + ' name= ' + pricename + ' > ' + Pricena Me + ' </button> '; $('. Price_btn '). CSS (' margin ', ' 5px ')); } $('. Weui-jiaj-money-box-btn '). Append ($titleHtml); //Select Amount$ ('. Price_btn '). Click (function() { varTitlevalue = $ ( This). attr (' name ');//$ (this) to get the name value of the element that is currently clicked vardata ={userid:userid, price:titlevalue}; Data=json.stringify (data); $.ajax ({data: {}, DataType:' JSON ', type:"POST", Url:postdoctorprice (). Replace ("{userid}", UserID). Replace ("{price}", Titlevalue), ContentType:' Application/json; Charset=utf-8 ', Success:function(data) {if(data && Data.status = = ' 200 ') {weui.toptips (' Submit Success '); }}, Error:function(data) {Location.href= ' doctor_wode.html '; } }); }); //Other Amount$ (' #otherPriceBtn '). On (' click ',function(e) {varOtherprice = $ (' #dialogPrice '). Val (); Otherprice=parseint (Otherprice); Otherprice=otherprice.tostring (); Console.log ("Other Amount" +Otherprice); vardata ={userid:userid, price:otherprice}; Data=json.stringify (data); $.ajax ({data: {}, DataType:' JSON ', type:"POST", Url:postdoctorprice (). Replace ("{userid}", UserID). Replace ("{price}", Otherprice),//URL with parameters at postContentType: ' Application/json; Charset=utf-8 ', Success:function(data) {if(data && Data.status = = ' 200 ') {weui.toptips (' Setup succeeded! ‘); }}, Error:function(data) {Location.href= ' doctor_wode.html '; } }); }); } //Validation$ (' input '). On (' Blur ',function(){ varValue = This. Value; varRegchinese =NewRegExp ("[\\u4e00-\\u9fff]+", "G"); //string cannot be empty if(Value.length = = 0) { $(' #otherPriceBtn '). Hide (); Weui.toptips (' Can't be empty '); //whether the string is an "empty" character and the user has entered a space}Else if(Value.replace (/(^s*) | ( s*$)/g, ""). Length ==0){ $(' #otherPriceBtn '). Hide (); Weui.toptips (' Can't be empty '); //whether the string is empty or all spaces}Else if(Value = =NULL){ $(' #otherPriceBtn '). Hide (); Weui.toptips (' cannot be null '); //whether the string is a Chinese character}Else if(Regchinese.test (value)) {$ (' #otherPriceBtn '). Hide (); Weui.toptips (' cannot enter Chinese characters '); //the string cannot be 0}Else if(parseint (value) = = 0){ $(' #otherPriceBtn '). Hide (); Weui.toptips (' Can't be 0 '); //cannot be greater than}Else if(parseint (value) > 200){ $(' #otherPriceBtn '). Hide (); Weui.toptips (' Custom amount cannot be greater than $200 '); //custom amounts can only be numbers}Else if(typeof(parseint (value))) { $(' #otherPriceBtn '). Show (); } }) </script>
Skillfully validating data with weui.toptips