如何檢查string 是英文或數字 ???
 发布于 12 年前  作者 hkmung  4927 次预览  最后一次回复是 12 年前  来自  

如何檢查string 是英文或數字 ???

6 回复
brighthas

use Regexp.


签名: 交流群244728015 《Node.js 服务器框架开发实战》 http://url.cn/Pn07N3

hkmung

var str = 'abc正則’ var objRE = new RegExp(/[a-zA-Z0-9_]*/) var match = str.match(objRE)

if (match[0].length>0){ console.log(‘match’) }else{ console.log(‘no match’) }

====================================== RegExp 不太懂 …

tomgor

isNaN(parseInt(str))

hkmung

var str = ‘abc正則’

var objRE = new RegExp(/[^a-zA-Z0-9_]/g) var match = str.match(objRE)

if(match==null){ console.log(‘match’) }else{ console.log(‘no match’) }

這個才正確