hash = window.location.hash.substr(1);var reg = new RegExp('^[0-9]$');console.log(reg.test(hash));我"123"和两者都是假的"123f"。我想检查散列是否只包含数字。我错过了什么?
3 回答
慕的地10843
TA贡献1785条经验 获得超8个赞
var validation = {
isEmailAddress:function(str) {
var pattern =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
return pattern.test(str); // returns a boolean
},
isNotEmpty:function (str) {
var pattern =/\S+/;
return pattern.test(str); // returns a boolean
},
isNumber:function(str) {
var pattern = /^\d+$/;
return pattern.test(str); // returns a boolean
},
isSame:function(str1,str2){
return str1 === str2;
}
};
alert(validation.isNotEmpty("dff"));
alert(validation.isNumber(44));
alert(validation.isEmailAddress("mf@tl.ff"));
alert(validation.isSame("sf","sf"));
添加回答
举报
0/150
提交
取消