简体   繁体   English

Google Recaptcha验证不适用于jQuery Form Validator

[英]google recaptcha validation not working with jquery form validator

My Problem : 我的问题 :

I have a registration form as a view in Codeigniter for which I have performed client side validation using Jquery Form validation. 我在Codeigniter中有一个注册表单作为视图,我已经使用Jquery Form验证为其执行了客户端验证。 The form validation is working perfectly fine for me . 表单验证对我来说很好。

However , I have the following problems with this form : 但是,此表格存在以下问题:

1.Recaptcha validation : I have a linking checkbox in this form which allows the user to fill in some more details and upload his company logo . 1.验证码验证:我在此表单中有一个链接复选框,该复选框允许用户填写更多详细信息并上传他的公司徽标。 When the user clicks on this checkbox , the jquery code simply adds a text box and a file upload option to upload the company logo . 当用户单击此复选框时,jQuery代码只需添加一个文本框和一个文件上载选项即可上载公司徽标。 (please see my jquery code to add the linking elements when the user checks the checkbox) (请查看我的jQuery代码,以在用户选中复选框时添加链接元素)

If the user does not click on this checkbox , and fills in all the input fields without selecting the recaptcha validation ,and presses submit button, the jquery form validator throws an error message and prompts the user to select the recpatcha validation . 如果用户未单击此复选框,并且在不选择重新验证的情况下填写了所有输入字段,然后按了提交按钮,则jQuery表单验证程序将抛出错误消息,并提示用户选择重新验证。

However when , the user clicks on the checkbox for linking option , fills in all the input fields without selecting the recaptcha validation and presses submit button , the page simply refreshes without giving an error message . 但是,当用户单击链接复选框时,填写所有输入字段而不选择Recaptcha验证,然后按Submit按钮,页面只是刷新而没有给出错误消息 The jquery form validator should ideally throw an error message and disallow the page to submitted if the user doesnt select the recaptcha validation . 理想情况下,如果用户未选择Recaptcha验证,则jQuery表单验证器应抛出错误消息并禁止提交页面。

The problem arises only when the user checks the checkbox for linking. 仅当用户选中用于链接的复选框时,才会出现此问题。

2.Terms and conditions checkbox validation : 2.条款和条件复选框验证:

If the user does not click on the linking checkbox option , fills in all the input fields without clicking on this checkbox ,and presses submit button, the jquery form validator throws an error message and prompts the user to select the terms and conditions checkbox . 如果用户未单击链接复选框选项 ,而不单击此复选框则填写所有输入字段,然后按提交按钮,则jQuery表单验证器将抛出错误消息,并提示用户选择条款和条件复选框。

However,when the user checks the linking checkbox , fills in all the input fields including recaptcha validation , but doesn't check the terms and conditions checkbox , and presses submit , the page simply refreshes without throwing an error message . 但是,当用户选中链接复选框,填写包括recapcha验证的所有输入字段,但不选中条款和条件复选框,然后按Submit时,页面仅刷新而不会引发错误消息。 The jquery form validator should ideally throw an error prompting the user to check the terms and conditions checkbox . 理想情况下,jQuery表单验证器应引发错误,提示用户检查条款和条件复选框。

Any help on this issue will be appreciated . 在这个问题上的任何帮助将不胜感激。

My code : 我的代码:

Registration form : 报名表格 :

<style>
.error{color:red;font-Style:Arial;font-Size:12px;};
</style>
<script src="https://www.google.com/recaptcha/api.js"></script>

<!-- Main Content -->
<div class="container-fluid">
  <div class="side-body">
    <!--post-resume-->
    <div class="row">
      <!--heading-->
      <hgroup class="m-b20">
        <h1 class="purple-bg">Information Technology Employers</h1>
      </hgroup>
      <!--content-->
      <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="row">
          <!--left-panel-->
          <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">         
            <!--<div style="text-align:left;" class="well well-sm">
                    <h2 class="m-t0">Support</h2>
                    <p>We recommend you to go through our FAQ section. </br> This might help you with most of your queries related to Membership | Login | Resume | Job </br> Still if you can't find what you're looking for, </p>
            </div>-->
            <div style="color:#ff0000"><?php //echo validation_errors(); ?></div>
            <form class="form-horizontal" role="form" id="myFrm" name="frmempsignup" method="post" action="<?php echo base_url();?>Employer/signup" enctype="multipart/form-data">

            <?php //echo form_open_multipart('Employer/signup', array('name'=>"frmempsignup", 'id'=>"myFrm", 'class'=>"form-horizontal", 'role'=>"form"));?>
              <div class="row">
                <?php if($this->session->flashdata('success')!=''){ ?>
                <?php echo $this->session->flashdata('success');?>
                <?php } ?>
                <div class="col-md-12">
                  <div class="panel panel-default">
                    <div class="panel-heading"><strong>Registration</strong> </div>
                    <div class="panel-body">
                      <!--f-->
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Company Name:</label>
                        <div class="col-md-9">
                        <input type="text" id="idcompany" name="company" class="form-control" placeholder="Company Name" value="<?php echo set_value('company'); ?>" />
                        <?php echo form_error('company', '<label class="error">','</label>'); ?>
                        </div>
                      </div>
                       <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Website:</label>
                        <div class="col-md-9">
                        <input type="text" id="idcompanyweb" name="companyweb" class="form-control" value="<?php echo set_value('companyweb'); ?>"/>
                        <?php echo form_error('companyweb', '<label class="error">','</label>'); ?>
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Full Name:</label>
                        <div class="col-md-9">
                          <input  type="text" id="name" name="fname" class="form-control" placeholder="Name" value="<?php echo set_value('fname'); ?>">
                          <?php echo form_error('fname', '<label class="error">','</label>'); ?>
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Corporate Email:</label>
                        <div id="iddivemail" class="col-md-9">
                          <input id="email_id" name="email" class="form-control m-t0" type="email" placeholder="Corporate Email" value="<?php echo set_value('email'); ?>">
                          <?php echo form_error('email', '<label class="error">','</label>'); ?>
                          <!--<div id="emailValidationDiv"></div>-->
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Password:</label>
                        <div class="col-md-9">
                          <input type="password" name="passwd" id="idpasswd" class="form-control m-t0" placeholder="Password" value="<?php echo set_value('passwd');?>">
                          <?php echo form_error('passwd', '<label class="error">','</label>'); ?>
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Confirm Password:</label>
                        <div class="col-md-9">
                          <input type="password" name="cpasswd" id="idcpasswd" class="form-control m-t0" placeholder="Password" value="<?php echo set_value('cpasswd');?>">
                          <?php echo form_error('cpasswd', '<label class="error">','</label>'); ?>
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Contact No:</label>                             
                      <div class="col-md-6">
                    <input name="mobno" class="form-control" type="text" id="idmobno" placeholder="Contact No" value="<?php echo set_value('mobno');?>">
                    <?php echo form_error('mobno', '<label class="error">','</label>'); ?>
                    </div>
                    <div class="col-md-3">
                    <input id="ext" name="ext" class="form-control" type="text" placeholder="Extension" value="<?php echo set_value('ext');?>">
                    </div>
                      </div>    
                      <div class="form-group">
                        <label class="col-md-3 control-label" style="text-align: left;">Address:</label>
                        <div class="col-md-9">
                          <input  id="idadd" name="add" class="form-control" type="text" placeholder="Enter your corporate address" value="<?php echo set_value('add');?>">
                          <?php echo form_error('add', '<label class="error">','</label>'); ?>
                        </div>
                      </div>
                      <div class="form-group" id="iddivemplink">
                        <label class="col-md-3 control-label " style="text-align: left;">Linking:
                        <span data-toggle="tooltip" data-placement="top" class="glyphicon glyphicon-info-sign" title=" Link your job-openings with techejobs through techejobs linking"></span></label>
                         <div class="col-md-9">
                        <input type="checkbox" name="emplink" id="idemplink" value="Y">
                        Link your job-openings with techejobs through techejobs linking
                       </div>
                       </div>                      
                      <div class="form-group">
                        <label class="col-md-3 control-label" ></label>
                        <div class="col-md-9">
                        <label><input type="checkbox" name="tc" id="tc">                        
                        I agree to the <a href="<?php echo base_url();?>terms">Terms & Conditions</a></label>
                        <?php echo form_error('tc', '<label class="error">','</label>'); ?>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3 control-label"></label>
                        <div class="col-md-9">
                          <!--<div class="g-recaptcha" data-sitekey="6Le3lxATAAAAAJ0NWNer-gPm2eZlG-8x2hEykOg7"></div>-->
                            <div class="g-recaptcha" data-sitekey="6LexRREUAAAAAELhZaiO5FxRbgnyWEwIxFTWeHhE" data-callback="recaptchaCallback"></div>
                            <input type="hidden" class="hiddenRecaptcha required" name="hiddenRecaptcha" id="hiddenRecaptcha">
                        </div>
                      </div>
                      </div>
                      <div class="form-group">
                        <div class="col-md-4 col-md-offset-3">
                          <input type="submit" value="Register" name="login" class="btn btn-primary btn-block" id="submitbutton">
                        </div>
                      </div>
                      <div class="form-group">
                        <label class="col-md-3"> </label>
                        <div class="col-md-9">Already registered? <a href="<?php echo base_url();?>Employer"> Login Here </a></div>
                      </div>
                      <!--f-->
                    </div>
                  </div>
                  <!--panel-->
                </div>
              </div>
            </form>
          </div>
          <!--right-panel-->
          <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
            <div class="panel panel-default">
                <div class="panel-heading"><strong>Registration</strong> </div>
                <div class="panel-body">                    
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                      <h3 class="m-t0">Sign up with the best job board</h3>
                      <video controls style="width:100%; height: auto; position:relative;">
                        <source src="<?php echo base_url(); ?>assets/video-tutorials/employer-signup/Employer-Promotional-Video.mp4" type="video/mp4">
                        <img src="<?php echo base_url(); ?>assets/video/bk_1.jpg" > </video>
                    </div>                                
                </div>
            </div>
            <!--panel-->            
            <ul class="list-unstyled list-group">
              <li class="list-group-item">
                <h3 class="m-tb0 text-danger">Simplified Talent Management Technology </h3>
                <h5 class="m-tb0">FREE Trial for 30 days...</h5>
              </li>
              <li class="list-group-item"><i class="fa fa-power-off text-danger"></i> Multiple job slots with unlimited posting</li>
              <li class="list-group-item"><i class="fa fa-eye text-danger"></i> 100 resume views</li>
              <li class="list-group-item"><i class="fa fa-thumbs-o-up text-danger"></i> Candidate marketing</li>
              <li class="list-group-item"><i class="fa fa-bars text-danger"></i> Matching, quality &amp; available resumes for all job postings</li>
              <li class="list-group-item"><i class="fa fa-envelope-o text-danger"></i> Dedicated customer support</li>
              <li class="list-group-item"><i class="fa fa-check-square-o text-danger"></i> Job distribution through network</li>
              <li class="list-group-item"><i class="fa fa-lightbulb-o text-danger"></i> Easy multiple location login</li>
            </ul>
          </div>
        </div>
        <!--/.row-->
      </div>
      <!--content-end-->
    </div>
    <!--post-resume-end-->
  </div>
</div>
<!-- Main Content end -->
<script>
function recaptchaCallback() {
  $('#hiddenRecaptcha').valid();
};

Jquery code to add and remove input fields when checkbox is checked : 选中复选框时添加和删除输入字段的jQuery代码:

/*jquery code added to add and remove techejobs linking elements */
    var linking = '<div id="iddivco" class="form-group">'+
                        '<hr style="display:block ; margin-top:-7px;border-top: 1px solid #cabfbf;border-top: 1px solid #cabfbf; width: 589px">'+
                        '<p style="padding-left:15px">Now, create your company page with ease. If you enable techejobs "Linking”, you need to fill up the details by providing an overview of your organization and a logo, and complete the registration process. After you register, your company profile page will be created.'+
                        'You can share the link of the page in social media for promotions where all your active jobs will be displayed.</p>'+
                        '<label class="col-md-3 control-label" style="text-align: left;">Company Overview</label>'+
                        '<div class="col-md-9">'+
                          '<textarea id="idco" name="txtcompanyoverview" class="form-control" ></textarea>'+
                          '</div>'+
                      '</div>'+
                      '<div id="iddivlogo" class="form-group">'+
                        '<label class="col-md-3" style="text-align: left;">Company Logo</label>'+
                        '<div class="col-md-9">'+
                          '<input  id="idlogo" name="logo" type="file">'+
                        '</div>'+
                      '</div>';         

    $('#idemplink').change(function()
    {
        if(this.checked) 
        {
            $(linking).insertAfter('#iddivemplink');            
        }
        else
        {
            $('#iddivco').remove();
            $('#iddivlogo').remove();
        }
    });

Jquery code for the registration form using jquery form validator : 使用jquery表单验证器的注册表单的jquery代码:

$("form[name='frmempsignup']").validate(
    {
        ignore: ".ignore",
        rules: 
        {
            "company":
            {
                required:true,
                companyname:true
            },          
            "companyweb":
            {
                required:true,
                url:true
            },          
            "email":
            {
                required: true,        
                email: true,
                //emailval:true,
                remote : 
                {
                    url: "/techejobs.dev/Employer/unique_email",
                    type: "post"
                }               
            },
            "fname":
            {
                required:true,
                fullnameval:true                
            },  
            "passwd":
            {
                required:true,
                minlength:6         
            },
            "cpasswd":
            {
              required : true,
              equalTo: "#idpasswd",
              minlength:6
            },          
            "mobno":{required:true},
            "ext":
            {
                digits: true,
                maxlength:5             
            },
            "add":{required:true},
            "tc":{required:true},
            "txtcompanyoverview":
            {
                required:true,
                minlength:120
                },
            "logo":
            {
                required:true,
                extension:"jpg|jpeg|png|gif",
                filesize:1000000                            
            },
            "hiddenRecaptcha": {
                required: function () {
                    if (grecaptcha.getResponse() == '') {
                        return true;
                    } else {
                        return false;
                    }
                }
            }            
        },
        messages:
        {
            "company":
            {
                required:"Please enter company name ",
                companyname:"Please enter a proper company name"
            },
            "companyweb":
            {
                required:"Please enter the web url of your company",
                url:"Please enter a valid url"
            },
            "fname":
            {
                required:"Please enter your full name",
                fullnameval:"Please enter a proper name"
            },          
            "email":
            {
                required:"Please enter your corporate email id",        
                email: "Please use a valid email format",
                emailval:"Please enter corporate email id only",
                remote:"Email already in use!"
            },
            "passwd":
            {
                required:"Please enter your password",
                minlength:"Password should have a minimum of 6 characters"
            },
            "cpasswd":
            {
                required : "Please confirm your password",
                equalTo  : "Passwords don't match",
                minlength:"Password should have a minimum of 6 characters"
            },
            "mobno":{required:"Please enter your contact no"},
            "ext":
            {
                digits:"Please enter a proper extension",
                maxlength:"Extension cannot be more than 5 digits"
            },
            "add":{required:"Please enter your address"},
            "tc":{required:"Please accept the terms and conditions to continue"},
            "txtcompanyoverview":
            {
                required:"Please enter your Company's overview",
                minlength:"Minimum 120 characters are needed"
            },
            "logo":
            {
                required:"Please upload your company logo",
                extension:"Only JPG,JPEG,PNG, and GIF files are allowed",
                filesize:"Filesize must be less than 1 MB"

            },
            "hiddenRecaptcha":
            {
               required :"Are you sure you’re not a robot?"
            }            
        },      
        errorPlacement: function( label, element )
        {
            if( element.attr( "name" ) === "tc" )
            {
                element.parent().append( label );
            } 
            else
            {
                label.insertAfter( element );
            }
        },
        submitHandler: function(form)
        {   
            return true;
        }        
    });

    $.validator.addMethod("emailval", function(value,element)
    {
        var n = value.lastIndexOf('@');
        var extension = value.substring(n+1).toLowerCase();
        if (extension == "gmail.com" || extension=="aol.com"|| extension=="facebook.com"|| extension=="googlemail.com"                  
            || extension=="hotmail.com" || extension=="hotmail.co.uk" || extension=="yahoo.com" || extension=="yahoo.co.uk"
            || extension=="live.com"    || extension=="att.net" || extension=="comcast.net" || extension=="gmx.com"     
            || extension=="mac.com" || extension=="me.com" || extension=="sbcglobal.net" || extension=="verizon.net"                
            || extension=="msn.com" || extension=="mail.com"|| extension=="email.com" || extension=="games.com"
            || extension=="gmx.net" || extension=="hush.com" ) 
        {
            return false ;
        } 
        else 
        {
            return true;
        }
    },
    function()
    {

    });

/*jquery code added to add and remove techejobs linking elements                            */
    var linking = '<div id="iddivco" class="form-group">'+
                        '<hr style="display:block ; margin-top:-7px;border-top: 1px solid #cabfbf;border-top: 1px solid #cabfbf; width: 589px">'+
                        '<p style="padding-left:15px">Now, create your company page with ease. If you enable techejobs "Linking”, you need to fill up the details by providing an overview of your organization and a logo, and complete the registration process. After you register, your company profile page will be created.'+
                        'You can share the link of the page in social media for promotions where all your active jobs will be displayed.</p>'+
                        '<label class="col-md-3 control-label" style="text-align: left;">Company Overview</label>'+
                        '<div class="col-md-9">'+
                          '<textarea id="idco" name="txtcompanyoverview" class="form-control" ></textarea>'+
                          '</div>'+
                      '</div>'+
                      '<div id="iddivlogo" class="form-group">'+
                        '<label class="col-md-3" style="text-align: left;">Company Logo</label>'+
                        '<div class="col-md-9">'+
                          '<input  id="idlogo" name="logo" type="file">'+
                        '</div>'+
                      '</div>';         

    $('#idemplink').change(function()
    {
        if(this.checked) 
        {
            $(linking).insertAfter('#iddivemplink');            
        }
        else
        {
            $('#iddivco').remove();
            $('#iddivlogo').remove();
        }
    });

My Research : I have gone through the following questions on Stack Overflow : 我的研究:我在堆栈溢出方面经历了以下问题:

1. reCaptcha v2 in conjunction with jQuery-Form-Validator 1. reCaptcha v2与jQuery-Form-Validator结合使用

2. New reCaptcha with jQuery Validation Plugin 2. 带有jQuery验证插件的新reCaptcha

3. how to test Recaptcha with jQuery Validate plugin 3. 如何使用jQuery Validate插件测试Recaptcha

Solution : 解决方案:

I found that the extension method of jquery form validator,for file upload , was the root cause of the issue . 我发现jquery表单验证程序的扩展方法 (用于文件上传 )是问题的根本原因。 When it was being used , the form validator was not throwing an error when terms and conditions checkbox and/or google recaptcha validation was not being checked . 当使用它时,如果未选中条款和条件复选框和/或Google Recaptcha验证,则表单验证程序不会引发错误。

When I replaced this method with a custom method fileextension using add method in Jquery form validator , the issue was resolved . 当我在Jquery表单验证器中使用add方法用自定义方法fileextension替换此方法时,问题已解决。 The form was getting validated and was throwing an error when terms and conditions checkbox and/or google recaptcha validation was not being checked. 当未选中条款和条件复选框和/或Google Recaptcha验证时,表单已通过验证并引发错误。

My Final Jquery code: 我的最终Jquery代码:

$("form[name='frmempsignup']").validate(
        {
            ignore: ".ignore",
            rules: 
            {
                "company":
                {
                    required:true,
                    companyname:true
                },          
                "companyweb":
                {
                    required:true,
                    url:true
                },          
                "email": 
                {
                    required: true,        
                    email: true,
                    emailval:true,
                    remote : 
                    {
                        url: "http://expinfo04-pc/techejobs.dev/Employer/unique_email",
                        type: "post"
                    }               
                },
                "fname":
                {
                    required:true,
                    fullnameval:true
                },  
                "passwd":
                {
                    required:true,
                    minlength:6         
                },
                "cpasswd":
                {
                  required : true,
                  equalTo: "#idpasswd",
                  minlength:6
                },          
                "mobno":{required:true},
                "ext":
                {
                    digits: true,
                    maxlength:5             
                },
                "add":{required:true},
                "tc":{required:true},
                "txtcompanyoverview":
                {
                    required:true,
                    minlength:120
                },
                "logo":
                {
                    required:true,
                    fileextension:true,
                    filesize:1000000
                },            
                "hiddenRecaptcha": 
                {
                    required: function () 
                    {
                        if (grecaptcha.getResponse() == '') 
                        {
                            return true;
                        } 
                        else 
                        {
                            return false;
                        }
                    },                
                }
            },
            messages:
            {
                "company":
                {
                    required:"Please enter company name ",
                    companyname:"Please enter a proper company name"
                },
                "companyweb":
                {
                    required:"Please enter the web url of your company",
                    url:"Please enter a valid url"
                },
                "fname":
                {
                    required:"Please enter your full name",
                    fullnameval:"Please enter a proper name"
                },          
                "email":
                {
                    required:"Please enter your corporate email id",        
                    email: "Please use a valid email format",
                    emailval:"Please enter corporate email id only",
                    remote:"Email already in use!"
                },
                "passwd":
                {
                    required:"Please enter your password",
                    minlength:"Password should have a minimum of 6 characters"
                },
                "cpasswd":
                {
                    required : "Please confirm your password",
                    equalTo  : "Passwords don't match",
                    minlength:"Password should have a minimum of 6 characters"
                },
                "mobno":{required:"Please enter your contact no"},
                "ext":
                {
                    digits:"Please enter a proper extension",
                    maxlength:"Extension cannot be more than 5 digits"
                },
                "add":{required:"Please enter your address"},
                "tc":{required:"Please accept the terms and conditions to continue"},
                "txtcompanyoverview":
                {
                    required:"Please enter your Company's overview",
                    minlength:"Minimum 120 characters are needed"
                },
                "logo":
                {
                    required:"Please upload your company logo",
                    extension:"Only JPG,JPEG,PNG, and GIF files are allowed",
                    filesize:"Filesize must be less than 1 MB"              
                },
                "hiddenRecaptcha":
                {
                    required :"Are you sure you’re not a robot?",
                }
            },      
            errorPlacement: function( label, element )
            {
                if( element.attr( "name" ) === "tc" ) 
                {
                    element.parent().append( label );
                } 
                else 
                {
                    label.insertAfter( element );
                }
            },
            submitHandler: function(form) 
            {   
                return true;
            }        
        });

        $.validator.addMethod("emailval", function(value,element)
        {
            var n = value.lastIndexOf('@');
            var extension = value.substring(n+1).toLowerCase();
            if (extension == "gmail.com" || extension=="aol.com"|| extension=="facebook.com"|| extension=="googlemail.com"                  
                || extension=="hotmail.com" || extension=="hotmail.co.uk" || extension=="yahoo.com" || extension=="yahoo.co.uk"
                || extension=="live.com"    || extension=="att.net" || extension=="comcast.net" || extension=="gmx.com"     
                || extension=="mac.com" || extension=="me.com" || extension=="sbcglobal.net" || extension=="verizon.net"                
                || extension=="msn.com" || extension=="mail.com"|| extension=="email.com" || extension=="games.com"
                || extension=="gmx.net" || extension=="hush.com" ) 
            {
                return false ;
            } 
            else 
            {
                return true;
            }
        },
        function()
        {

        });

        $.validator.addMethod("fileextension", function(value,element)
        {
            var n = value.lastIndexOf('.');
            var extension = value.substring(n+1).toLowerCase();
            if (extension == "png" || extension=="gif"|| extension=="jpg"||extension=="jpeg")
            {
                return true ;
            }
            else 
            {
                return false;
            }
        },
        function()
        {
        });

        //frmempsignup: name of company : first character alphanumeric , onlyalphanumeric , dot,spaces,& allowed
        $.validator.addMethod("companyname", function(value,element)
        {       
            if (/^[a-zA-Z0-9][a-zA-Z0-9. &,-_',]{1,256}$/.test(value))
            {
                return true;
            } 
                else 
            {
                return false;
            }       
        },function() 
        { 
        });     

        //frmempsignup :full name : first character alpha, only alphanumeric and spaces allowed
        $.validator.addMethod("fullnameval", function(value,element)
        {       
            if (/^[a-zA-Z][a-zA-Z0-9 ]{0,256}$/.test(value)) 
            {
                return true;
            } 
            else 
            {
                return false;
            }       
        },function() 
        {           
        });

        //frmempsignup : company url : only valid urls allowed , http://,https://,wwww,ftp://
        $.validator.addMethod("urlval", function(value,element)
        {   
            //"^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)"
            //var urlregex = new RegExp("^(http:\/\/|https:\/\/|ftp:\/\/|www.){1}([0-9A-Za-z]+\.)");
            var urlregex = new RegExp("^(http:\/\/|https:\/\/|ftp:\/\/|www.)([0-9A-Za-z]+\.)+(aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|cz|de|dj|dk|dm|do|dz|ec|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mn|mn|mo|mp|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|nom|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ra|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw|arpa)(:[0-9]+)?((\/([~0-9a-zA-Z\#\+\%@\.\/_-]+))?(\?[0-9a-zA-Z\+\%@\/&\[\];=_-]+)?)?))\b/imuS");
            if (urlregex.test(value)) 
            {
                return true;
            } 
            else 
            {
                return false;
            }       
        },function() 
        {           
        }); 

        //frmempsignup : company logo : filesize must be less than 1 MB
        $.validator.addMethod('filesize', function (value, element, param) {
                    return this.optional(element) || (element.files[0].size <= param)
                    }, 'File size must be less than {0}');  

    }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM