0

I have below script:

$(function() {
    $(".submit").click(function() {
        var full_name = $("#full_name").val();
        var cell_phone = $("#cell_phone").val();
        var email = $("#email").val();
        var dataString = 'full_name='+ full_name + '&cell_phone=' + cell_phone + '&email=' + email;
        if (full_name=='' || cell_phone=='' || email=='')
        {   
            $('.success').fadeOut(200).hide();
            $('.error').fadeOut(200).show();      
        }   
        else 
        {
            $.ajax({
                type: "POST",
                url: "join.php",
                data: dataString,
                success: function() {
                    $('.submit').fadeIn(200).hide();
                    $('.success').fadeIn(200).show();
                    $('.error').fadeOut(200).hide();
                }
            });
        }
        return false;
    });
});
  1. How to make validate email.
  2. Only ( numbers + - ) and not less than 7 numbers for cell_phone filed.
RobG
  • 142,382
  • 31
  • 172
  • 209
Saeed Aknan
  • 93
  • 1
  • 7

2 Answers2

0

is.js's email and phone validators can be solution.

$(function() {
    $(".submit").click(function() {
        var full_name = $("#full_name").val();
        var cell_phone = $("#cell_phone").val();
        var email = $("#email").val();
        var dataString = 'full_name='+ full_name + '&cell_phone=' + cell_phone + '&email=' + email;
        if (full_name=='' || is.not.eppPhone(cell_phone) || is.not.email(email))
        {   
            $('.success').fadeOut(200).hide();
            $('.error').fadeOut(200).show();      
        }   
        else 
        {
            $.ajax({
                type: "POST",
                url: "join.php",
                data: dataString,
                success: function() {
                    $('.submit').fadeIn(200).hide();
                    $('.success').fadeIn(200).show();
                    $('.error').fadeOut(200).hide();
                }
            });
        }
        return false;
    });
});
Berkay Yildiz
  • 595
  • 7
  • 23
0
var re = /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
var phoneno = /^\+?(?:[0-9] ?){6,14}[0-9]$/;
if (full_name=='' || !phoneno.test(cell_phone) || !re.test(email))
Saeed Aknan
  • 93
  • 1
  • 7