我試圖檢查字符串是否都是a-zA-Z0-9
但這不起作用。任何想法爲什麼?用於檢查字符串是否爲a-zA-Z0-9的正則表達式
var pattern=/^[a-zA-Z0-9]*$/;
var myString='125 jXw'; // this shouldn't be accepted
var matches=pattern.exec(myString);
var matchStatus=1; // say matchStatus is true
if(typeof matches === 'undefined'){
alert('within here');
matchStatus=0; // matchStatus is false
};
if(matchStatus===1){
alert("there was a match");
}
您的STRING一個白色的空間,所以它不符合你的模式。 – 2013-03-11 19:32:39
這是故意的 – timpone 2013-03-11 19:34:33
var pattern =/^ [a-zA-Z0-9 \ s] * $ /; – Girish 2013-03-11 19:36:38