2012-04-24 35 views

回答

15
if (p.match(/[^$,.\d]/)) 
    alert('error!'); 

Live DEMO

您可以使用this優秀正則表達式小抄。

2

考慮:

if (/[^$,\.\d]/.test(p)) { 
    // value has characters other than $ , . 0-9. 
}; 

正則表達式測試方法返回一個布爾值,而匹配返回一個數組並因此在simlar方式使用時是依賴於類型轉換。

相關問題