$(function() {
$("input[name =companyname]").blur(function(){
var str = $("#companyname").val();
var patn = /^([\u4e00-\u9fa5]|[A-Za-z]|[0-9])+$/;
var path=$("#path").val();
if (str.length < 4 || str.length > 30) {
showInfo($("#companyname_msg"),'公司名称必须为4-30个字符','err');
$("#is_companyname").val("0");
}
else if (!patn.test(str)) {
showInfo($("#companyname_msg"),'公司名称不能含特殊字符','err');
$("#is_companyname").val("0");
} else if (IsEnglishCharacterValedate(str)) {
showInfo($("#companyname_msg"),'公司名称不能为纯英文','err');
$("#is_companyname").val("0");
return false;
}
/*验证是否数字*/
else if (IsNumCharacterValedate(str)) {
showInfo($("#companyname_msg"),'公司名称不能为纯数字','err');
$("#is_companyname").val("0");
}
else {
showInfo($("#companyname_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_companyname").val("1");
}
});
$("input[name =username]").blur(function() {
var path=$("#path").val();
var v = $("input[name =username]").val();
len=v.replace(/[^\x00-\xff]/g, 'xx').length,
isName=/[^\u4e00-\u9fa50-9a-zA-Z]/ig.test(v),
isNum=/^\d+$/.test(v);
var o=$("#user_name");
if(!v){
showInfo($("#username_msg"),'用户名不能为空','err');
$("#is_username").val("0");
return false;
}else if(len<6||len>20){
showInfo($("#username_msg"),'用户名长度为6-20个字符','err');
$("#is_username").val("0");
return false;
}else if(isNum){
showInfo($("#username_msg"),'用户名不能以纯数字组成','err');
$("#is_username").val("0");
return false;
}else if(isName){
showInfo($("#username_msg"),'用户名不能有特殊字符存在','err');
$("#is_username").val("0");
return false;
}
$.ajax({
type : "get",
url : path + "/supplier/getName", // 请求路径
data : "name=" + v, // 传参
cache : false,
dataType : "text",
success : function(msg) {
if (msg == "ok") {
showInfo($("#username_msg"),"<img src='"+path+"/images/success.png'/>","ok");
$("#is_username").val("1");
} else {
showInfo($("#username_msg"),'系统内已存在相同用户名','err');
$("#is_username").val("0");
}
},
error : function(XMLResponse) {
alert("错误");
}
});
/*}else{
}*/
});
$("input[name=password]").keyup(function(){
var path=$("#path").val();
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
$('#password_img').css("display","block");
if (false == enoughRegex.test($(this).val())) {
$('#password_img').attr("src",path+"/images/1.jpg");
showInfo($("#password_msg"),'密码位数不够','err');
$("#is_userpass").val("0");
}else if(IsEnglishCharacterValedate($(this).val())){
$('#password_img').attr("src",path+"/images/1.jpg");
showInfo($("#password_msg"),'密码不能为纯英文','err');
$("#is_userpass").val("0");
}else if(IsNumCharacterValedate($(this).val())){
$('#password_img').attr("src",path+"/images/1.jpg");
showInfo($("#password_msg"),'密码不能为纯数字','err');
$("#is_userpass").val("0");
}else if (strongRegex.test($(this).val())) {
$('#password_img').attr("src",path+"/images/4.jpg");
showInfo($("#password_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_userpass").val("1");
} else if (mediumRegex.test($(this).val())) {
$('#password_img').attr("src",path+"/images/3.jpg");
showInfo($("#password_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_userpass").val("1");
} else {
$('#password_img').attr("src",path+"/images/2.jpg");
showInfo($("#password_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_userpass").val("1");
}
return true;
});
//检查二次密码
$("input[name=password2]").blur(function(){
var path=$("#path").val();
if($('#password').val() != $('#password2').val()){
showInfo($("#password2_msg"),'两次密码不相同','err');
$("#is_userpass2").val("0");
return false;
}else if($('#password2').val()==""){
showInfo($("#password2_msg"),'请再次确认密码','err');
$("#is_userpass2").val("0");
return true;
}else{
showInfo($("#password2_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_userpass2").val("1");
return true;
}
});
//检查身份证
$("input[name =idcard]").blur(function(){
var path=$("#path").val();
var idcard=$("#idcard").val();
var bo=/^(\d{6})(18|19|20)?(\d{2})([01]\d)([0123]\d)(\d{3})(\d|X)?$/.test(idcard);
var year = idcard. substr(6,4);
var month = idcard. substr(10,2);
var day = idcard. substr(12,2);
if(bo==false||month>12||day>31){
showInfo($("#idcard_msg"),'请填写正确身份证号码','err');
$("#is_idcard").val("0");
return false;
}
else{
showInfo($("#idcard_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_idcard").val("1");
}
});
//检查手机
$("input[name =mobile]").blur(function(){
var path=$("#path").val();
var v = $("#mobile").val();
var o = $("#mobile");
isBirthdate= /^1[0-9][0-9]\d{4,8}$/.test(v);
if(isBirthdate == 0){
showInfo($("#mobile_msg"),'请填写正确的手机号码','err');
$("#is_phone").val("0");
}
else{
showInfo($("#mobile_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_phone").val("1");
}
});
//检查联系人
$("input[name =linkman]").blur(function(){
var path=$("#path").val();
var name=$("#linkman").val();
var reg = /^[\u4e00-\u9fa5a-z][\u4e00-\u9fa5a-z0-9_]*$/i;
var name_Flag = reg.test(name);
if(name_Flag){
showInfo($("#linkman_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_linkman").val("1");
}else{
showInfo($("#linkman_msg"),'姓名只能是英文、汉字、数字','err');
$("#is_linkman").val("0");
}
});
//检查邮编
$("input[name=postcode]").blur(function(){
var str = $("#postcode").val();
var pattern = /^[0-9]{6}$/;
if (!pattern.test(str)){
showInfo($("#postcode_msg"),'邮编只能是6位数字','err');
$("#is_postcode").val("0");
return false;
}else{
showInfo($("#postcode_msg"),'通过验证','ok');
$("#is_postcode").val("1");
return true;
}
});
//检查地址
$("input[name=address]").blur(function(){
var str =$("#address").val();
var path=$("#path").val();
var patn = /^([\u4e00-\u9fa5]|[A-Za-z]|[0-9])+$/;
if (str.length < 4 || str.length > 50) {
showInfo($("#address_msg"),'地址必须为4-50个字符','err');
$("#is_address").val("0");
}
else if (IsNumCharacterValedate(str)) {
showInfo($("#address_msg"),'公司地址不能为纯数字','err');
$("#is_address").val("0");
}
else if (!patn.test(str)) {
showInfo($("#address_msg"),'地址不能包含特殊字符','err');
$("#is_address").val("0");
} else {
showInfo($("#address_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_address").val("1");
}
});
//检查email
$("input[name =email]").blur(function(){
var path=$("#path").val();
var v = $("#email").val();
var o = $("#email");
isEmail=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(v);
if(isEmail==false){
showInfo($("#email_msg"),'邮件地址格式输入错误','err');
$("#is_email").val("0");
return false;
}else{
showInfo($("#email_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_email").val("1");
}
});
//检查公司号码
$("input[name =companyphone]").blur(function(){
var path=$("#path").val();
var number=$("#companyphone").val();
var isMobile=/^(?:1\d{2})\d{5}(\d{3}|\*{3})$/;
var isPhone=/^((0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/;
if(!isMobile.test(number) && !isPhone.test(number)){
showInfo($("#companyphone_msg"),'请正确填写电话号码<br>例如:13101234567或021-12345678','err');
$("#is_companyphone").val("0");
}else{
showInfo($("#companyphone_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_companyphone").val("1");
}
});
//检查qq
$("input[name=qq]").blur(function(){
var path=$("#path").val();
var qq=$("#qq").val();
if(!IsNumCharacterValedate(qq)){
showInfo($("#qq_msg"),"QQ号应为纯数字",'err');
$("#is_companyphone").val("0");
}else{
showInfo($("#qq_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_qq").val("1");
}
});
});
function check_step_1(){
$("input[name=password2]").blur();
var path=$("#path").val();
var username=$("#is_username").val();
var userpass=$("#is_userpass").val();
var userpass2=$("#is_userpass2").val();
var yzm=$("#is_yzm").val();
if(username=="0"){
$("#username").focus();
return false;
}else if(userpass=="0"){
$("#password").focus();
return false;
}else if(userpass2=="0"){
$("#password2").focus();
return false;
}else if(yzm=="0"){
$("#yzm").focus();
return false;
}else{
form.submit();
}
}
function check_step_2(){
var companyname=$("#is_companyname").val();
var companyphone=$("#is_companyphone").val();
var linkman=$("#is_linkman").val();
var address=$("#is_address").val();
var mobile=$("#is_phone").val();
var qq=$("#is_qq").val();
var email=$("#is_email").val();
var tiaokuan=$("#bawangtiaokuan").attr("checked");
if(companyname=="0"){
$("#companyname").focus();
return false;
}else if(companyphone=="0"){
$("#companyphone").focus();
return false;
}else if(linkman=="0"){
$("#linkman").focus();
return false;
}else if(address=="0"){
$("#address").focus();
return false;
}else if(mobile=="0"){
$("#mobile").focus();
return false;
}else if(qq=="0"){
$("#qq").focus();
return false;
}else if(email=="0"){
$("#email").focus();
return false;
}else if(!tiaokuan){
alert("请仔细阅读并同意注册条款");
return false;
}else{
form.submit();
}
}
function showInfo(o, m, s) {
var s = s || "";
switch (s) {
case "err":
o.html(m).removeClass("ok").show().addClass(s);
var input_o=o.attr("id").replace("_msg","");
$("#"+input_o).addClass("input_err").show();
break;
case "ok":
o.html(m).removeClass("err").show();
var input_o=o.attr("id").replace("_msg","");
$("#"+input_o).removeClass("input_err").show();
break;
default:
// o.html(m).removeClass("err ok").show().addClass(s);
break;
}
}
function checkyzm(){
var path=$("#path").val();
var check="";
var check_local=$("#yzm").val();
if(check_local==""){
showInfo($("#yzm_msg"),"请输入验证码",'err');
$("#is_yzm").val("0");
}else{
$.ajax({
url:path+"/supplier/getCheck",
type:"get",
cache : false,
dataType : "text",
success:function(data){
check=data;
if(check_local.toUpperCase()==check){
showInfo($("#yzm_msg"),"<img src='"+path+"/images/success.png'/>",'ok');
$("#is_yzm").val("1");
}else{
showInfo($("#yzm_msg"),"验证码不正确",'err');
$("#is_yzm").val("0");
}
}
});
}
}
function change() {
var path = $("#path").val();
$("#image").attr("src", path+"/images/yanzhengma/image.jsp");
}
/*验证是否全英文*/
function IsEnglishCharacterValedate(strin) {
var patrn = /^[A-Za-z]+$/;
if (!patrn.exec(strin)) return false;
return true;
}
/*验证是否全数字*/
function IsNumCharacterValedate(strin) {
var patrn = /^[0-9]+$/;
if (!patrn.exec(strin)) return false;
return true;
}
常用js验证数据的有效性
最新推荐文章于 2024-04-13 01:42:20 发布