2013-08-23 14 views
0

我試圖使用jquery validationengine檢查MAC被驗證與否,validationengine ,我添加一個名爲「onlyMAC」這樣的自定義屬性:我的正則表達式中的jQuery不工作validationenging

"onlyMAC":{ 
"regex":"/^([A-Z0-9]){16}$/", 
"alertText":"* MAC invalid"} 

和形式:

<form id='myform'> 
<input name="mac" type="text" value="" class="validate[required,custom[onlyMAC]]"/> 
</form> 
<script> 
$('#myform').validationEngine(); 
</script> 

但無論我爲mac輸入,validationEngine總是返回該alertText:「* MAC無效」。 我在這裏檢查了我的正則表達式http://jsfiddle.net/chennet/LRfW6/,看起來很好。 那麼,我做錯了什麼?

回答

0

有文檔中看看例子:https://github.com/posabsolute/jQuery-Validation-Engine#selectors

從你的正則表達式定義中刪除引號:

"onlyMAC":{ 
"regex":/^([A-Z0-9]){16}$/, 
"alertText":"* MAC invalid"} 

的問題是,你混合使用正則表達式構造正則表達式語法:

/^([A-Z0-9]){16}$/ // RegExp literal uses the slashes 
new RegExp('^([A-Z0-9]){16}$') // RegExp constructor takes a string (without the slashes). 
+0

哇,它的工作,謝謝。我想知道爲什麼由validationengine定義的那些原始文件正在工作,即使他們有正則表達式的引用? – user2189138

+0

我看到的例子都沒有引用正則表達式。你在看哪個例子? –