正则表达式

var defreg = {
		"img": /(\.|\/)(gif|jpe?g|png)$/i,
		"doc": /(\.|\/)(pdf|doc|docx|ppt|pptx)$/i,
		"mobile": /^0?(13|15|18|14|17)[0-9]{9}$/,
		"email": /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/,
		"emailmobile": /^1\d{10}$|^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/,
		"password": /^[^\u4E00-\u9FA5\uF900-\uFA2D\u0020]{6,16}$/,
		"loginname": /^[^\u4E00-\u9FA5\uF900-\uFA2D\u0020]{26}$/,
		//"password":/^[0-9a-zA-Z]{8,16}$/,
		"url": /((https|http|ftp|rtsp|mms):\/\/)?(([0-9a-z_!~*'().&=+$%-]+:)?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\.[a-z]{2,6})(:[0-9]{1,4})?((\/?)|(\/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+\/?)/g,
		"mobilecode": /^\d{6}$/,
		"yaocode": /^\d{6}$/,
		"realname": /^[\u4e00-\u9fa5]{2,5}$/i,
		"amount": /^[0-9]+([.]{1}[0-9]{1,2})?$/,
		"vcode": /^\w{4}$/
	}

  

function defcheck(str, f) {
	if (defreg.hasOwnProperty(f) && defreg[f].test(str)) {
		return true;
	} else {
		return false;
	}
}

  

posted @ 2017-02-16 18:04  宫圆薰  阅读(192)  评论(0编辑  收藏  举报