2012-04-24 32 views

回答

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

Live DEMO

您可以使用this优秀正则表达式小抄。

2

考虑:

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

正则表达式测试方法返回一个布尔值,而匹配返回一个数组并因此在simlar方式使用时是依赖于类型转换。

相关问题