我正在使用jquery.validationengine.en.js來(自定義)驗證我的表單字段。對於一個字段,我使用兩個自定義驗證。我不想同時顯示字段的驗證消息。它一次只能顯示一個味精。怎麼做?結合兩個正則表達式
請在下面的代碼找到 注意:allzero也被其他一些領域使用。
"phone": {
"regex": /^[0-9]{8,15}$/,
"alertText": "* Invalid phone number"
},
"allzero": {
"regex": /([^((\+)*(0*))])/,
"alertText": "* Invalid number"
},
HTML代碼:
<input type="text" name="phone" id="phone" class="textBox textNormal validate[maxSize[30],custom[onlyNumberSp],custom[phonenumber],custom[allzero]]" onfocus="jQuery('#adduserform').validationEngine('attach',{Overflown:false})">
<input type="text" name="mobile" id="mobile" class="textBox textNormal validate[maxSize[30],custom[onlyNumberSp],custom[mobile],custom[allzero]]" value="" onfocus="jQuery('#adduserform').validationEngine('attach',{Overflown:false})">
你能表現出一定的代碼?具體來說,兩個驗證規則的定義是什麼? –
添加代碼。請檢查 – Nila
如果您的第一個正則表達式只允許數字,爲什麼第二個正則表達式允許任意數量的前導加號?無論如何,第二個正則表達式很糟糕 - 大概你的意思是類似'/^\ +?0 * $ /'? – tripleee