How to Add a Custom Function in Jquery Form Validator

How to Add a Custom Function in Jquery Form Validator?

 

First, write the custom function like below.

jQuery.validator.addMethod("mobile_prefix", function(value, element) 
{

        var select=true;

        var mobile_prefix=$("#mobile_prefix").val();

        if(value && !mobile_prefix)
        {
            select=false;
        }

        return select;

    });

 

Secondly, In the form validator function call the above custom defined function. It will return TRUE / FALSE.

 

 $("#form").validate({

        rules:{
            "password":{
                required:true,
                noSpace: true
            },
            "confpassword": {
                equalTo:"#passwordd"
            },
            "mobile_number":{
                required:true,
                requiredcustom:true,
                numericvalue:true,
                mobile_prefix:true
            },
          },  

          messages: {
            "confpassword": {
                required:"Enter confirm password",
                equalTo: "Password mismatch",
            },
            "password":{
                required:"Enter password",
                noSpace : "no space please."
            },
            "mobile_number": {
                required: "Enter Mobile Number",
                minlength: "Mobile number atleast 10",
               mobile_prefix:"Please select code"
            },
        },
    });

If you like the post, please comment below & follow us on social platform.

Validation Rules for Email CodeIgniter version 3.17

I am used to CodeIgniter .

I just started to working in CodeIgniter 3.17, and reached to validation rules.

I notice that xss_clean is now gone from the validation class, so what rules should I use in the validation of email ?

$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');

For More Visit Codeigniter website :

https://www.codeigniter.com/userguide3/libraries/form_validation.html

Check if input is valid number in Jquery or Javascript

It Returns TRUE or FAlSE.
If Valid Number It Returns True , Otherwise False.

<script>
function CheckValidPrice(price=0){     
    var tempPrice = Math.round(price * 100)/ 100;     
    var RE = /^(?!^0*$)(?!^0*\.0*$)^\d{1,7}(\.\d{1,2})?$/;
    if(RE.test(tempPrice))
    {         
        return true;     
    }
    else
    {       
        return false;     
     }     
}
</script>

Email Validation check in javascript

## Used To Validate Email In Javascript <script >   function validateEmail(email) {     var emailReg = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;     return emailReg.test( email );   } </script>

Form validation using jQuery in php

## form validation in JQuery <script type=”text/javascript”> $(document).ready(function(){    $(‘#send_enquiry’).click(function(){ var get_validate = validateForm();        console.log(get_validate); if(get_validate>0){    return false; }else{    return true; } }); function validateForm(){   var facedError = 0;   var nameReg   = /^[A-Za-z]+$/;   var numberReg =  /^[0-9]+$/;  var emailReg  = /^([\w-\.][email protected]([\w-]+\.)+[\w-]{2,4})?$/;   var names     … Read moreForm validation using jQuery in php