在貍米學(xué)習(xí)定義的各種驗證字段,思路還是比較好的,
/**
* 驗證名字是否為1到4位的中文字符
* @author wu.yu
* @version 2.0.1
*
* */
Object.defineProperty(String.prototype,"isMobile",{
get:function () {
return /^1[34578]\d{9}$/.test(this);
}
});
/**
* 驗證名字是否為1到4位的中文字符
* @author wu.yu
* @version 2.0.1
* */
Object.defineProperty(String.prototype,"isChineseName",{
get:function () {
return /^[\u4E00-\u9FA5]{2,4}$/.test(this);
}
});
/**
* 檢驗短信驗證碼是否為4位數(shù)字
* @author wu.yu
* @version 2.0.1
* */
Object.defineProperty(String.prototype,"isValidateCode",{
get:function () {
return /^\d{4}$/.test(this);
}
});
console.obj= function (obj) {
this.log(JSON.stringify(obj,null,4))
}
window.lg={
obj:function (obj) {
console.log(JSON.stringify(obj,null,4))
}
}