Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7925891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:29:28+00:00 2026-06-03T18:29:28+00:00

Possible Duplicate: JQuery validate e-mail address regex hi i have an input filed in

  • 0

Possible Duplicate:
JQuery validate e-mail address regex

hi i have an input filed in a form referencing to an email input field , and when the user clicked the submit button i want to ensure that the email input field value has the formal like this

example@hotmail.com

or

example@gmail.com

or

example@yahoo.com

and the input field is this

<p>
            <label>Email</label>
            <input type="text" name="Email"/>
            <span class="errorMessage"></span>
        </p>

jquery code

$(document).ready(function(){
    $('#suform').on('submit', function(e){
        e.preventDefault();
        var errorCount = 0;
        $('span.errorMessage').text(''); // reset all error mesaage
        $('input').each(function(){
            var $this = $(this);
            if($this.val() === ''){
                var error = 'Please fill ' + $this.prev('label').text(); // take the input field from label
                $this.next('span').text(error);
                errorCount = errorCount + 1;   
            }
        });
        if(errorCount === 0){
            var mobileNumber = $('input[name=MNumber]');
            var email = $('input[name=Email]');
            if(isNaN(parseFloat(mobileNumber )) && !isFinite(mobileNumber )) {
                var error = 'Mobile number incorect.';
                $('input[name=MNumber]').next('span').text(error);
                errorCount = errorCount + 1; 
            }else{      
                var password= $('input[name="Password"]').val();
                var repass= $('input[name="RePassword"]').val();
                if(password!=repass){ // ensrue the two passwords are the same
                    var error2 = 'Password not matching';
                    $('input[name="RePassword"]').next('span').text(error2)
                    errorCount = errorCount + 1;  
                }else{
                    $(this)[0].submit(); // submit form if no error
                }
            }
        }
    });
});

my html , css and jquery code is here
code

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T18:29:31+00:00Added an answer on June 3, 2026 at 6:29 pm

    If I understand you correctly, you want to validate the email address filled on the form:

    ADD TO YOUR FUNCTION

    // validate proper email address
    var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
    
    if (reg.test(value) == false) {
      // email invalid, do stuff
    } else {
      // email valid, do stuff
    }
    

    This Regular expression checks the email provided for many many many issues!

    EDITED:

    You’re function had some typos, here it is fully functional: and a working Fiddle!

    $(document).ready(function(){
    
        // form submit
        $('#suform').on('submit', function(e){
    
            // prevent default behavior
            e.preventDefault();
    
            // reset errors counter
            var errorCount = 0;
    
            // clear error message
            $('span.errorMessage').text('');
    
            // run by each input field to check if they are filled
            $('input').each(function(){
    
                var $this = $(this);
    
                if($this.val() === ''){
                    // take the input field from label
                    var error = 'Please fill ' + $this.prev('label').text();
                    $this.next('span').text(error);
                    errorCount = errorCount + 1;   
                }
            });
    
            // no errors so far, let continue and validate the contents
            if(errorCount === 0){
    
                // get mobile number
                var mobileNumber = $('input[name=MNumber]').val();
    
                // get email address
                var email = $('input[name=Email]').val();
    
                // get password and password repeat
                var password= $('input[name="Password"]').val();
                var repass= $('input[name="RePassword"]').val();
    
                // regular expression to validate the email address
                var reg = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
    
                // try to validate the email
                if (reg.test(email) == false) {
                  $('input[name=Email]').next('span').text('Email address is invalid!');
                  errorCount = errorCount + 1;
                } else {
    
                    if(isNaN(parseFloat(mobileNumber )) && !isFinite(mobileNumber )) {
                        var error = 'Mobile number incorect.';
                        $('input[name=MNumber]').next('span').text(error);
                        errorCount = errorCount + 1;
                    } else {
                        // ensrue the two passwords are the same
                        if(password!=repass){
                            var error2 = 'Password not matching';
                            $('input[name="RePassword"]').next('span').text(error2);
                            errorCount = errorCount + 1;  
                        }else{
                            $(this)[0].submit(); // submit form if no error
                        }
                    }
                }
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jQuery: get the file name selected from <input type=file /> I have
Possible Duplicate: Detect all changes to a <input type=text> (immediately) using JQuery I have
Possible Duplicate: Submit a form using jQuery $('#form') Supposed the jQuery Object of the
Possible Duplicate: jQuery scroll To Element Basically, I want my user to be instantly
Possible Duplicate: jQuery Youtube URL Validation with regex YouTube url id Regex http://www.youtube.com/watch?v=SCS7SIeF30E http://www.youtube.com/watch?v=SCS7SIeF30E&feature=relmfu
Possible Duplicate: jQuery - is it bad to have multiple $(document).ready(function() {}); Can you
Possible Duplicate: jquery/ajax load new content when available i have a table named news
Possible Duplicate: jquery trigger - ‘change’ function I have a radio button set called
Possible Duplicate: jquery validate & ajax.beginform I'm trying to use the jQuery validate plugin
Possible Duplicate: What does jQuery.fn mean? I have some script on a page trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.