1:URL的判断
function IsURL(str_url){ var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //ftp的user@ + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184 + "|" // 允许IP和DOMAIN(域名) + "([0-9a-z_!~*'()-]+\.)*" // 域名- www. + "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名 + "[a-z]{2,6})" // first level domain- .com or .museum + "(:[0-9]{1,4})?" // 端口- :80 + "((/?)|" // a slash isn't required if there is no file name + "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$"; var re=new RegExp(strRegex); //re.test() if (re.test(str_url)){ return true; }else{ scscms_alert("网址不合法","warn"); return false; } }
2:注册用到:
$(document).ready(function(){ $.formValidator.initConfig({formid:"form1",debug:false,submitonce:true, onerror:function(msg,obj,errorlist){ //$.map(errorlist,function(msg1){scscms_alert(msg1)}); scscms_alert(msg); } }); $("#user_name").formValidator({onshow:"至少4个字符",onfocus:"数字、字母或划线",oncorrect:"通过"}).inputValidator({min:4,empty:{leftempty:false,rightempty:false,emptyerror:"输入有误"},onerror:"输入有误"}).regexValidator({regexp:"^(?!_)(?!.*?_$)[a-zA-Z0-9_]+$",onerror:"包含非法字符!"}); $("#psd").formValidator({onshow:"至少6个字符",onfocus:"至少6个字符",oncorrect:"密码合法"}).inputValidator({min:6,empty:{leftempty:false,rightempty:false,emptyerror:"输入有误"},onerror:"输入有误"}); $("#psd_sure").formValidator({onshow:"请再次输入密码",onfocus:"请再次输入密码",oncorrect:"密码一致"}).inputValidator({min:6,empty:{leftempty:false,rightempty:false,emptyerror:"输入有误"},onerror:"输入有误"}).compareValidator({desid:"psd",operateor:"=",onerror:"密码不一致"}); $("#contact_name").formValidator({onshow:"至少4个字符",onfocus:"至少4个字符",oncorrect:"通过"}).inputValidator({min:4,empty:{leftempty:false,rightempty:false,emptyerror:"输入有误"},onerror:"输入有误"}); $("#email").formValidator({onshow:"6-100个字符",onfocus:"6-100个字符",oncorrect:"恭喜你,你输对了"}).inputValidator({min:6,max:100,onerror:"长度非法"}).regexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"格式不正确"}); });
3:邮箱验证:
//邮箱验证 function isEmail(strEmail) { if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$ /) != -1){ $("#check_email").html(""); return true; } else{ $("#check_email").html("<font color='red'><br>请输入正确格式邮箱!</font>"); return false; } }
4:去空格:
function ltrim(s){ return s.replace( /^\s*/, ""); } //去右空格; function rtrim(s){ return s.replace( /\s*$/, ""); } function trim(s){ return rtrim(ltrim(s)); }
5