SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jquery form validation regular expression

    The following checks if anything at all has been entered.

    Code:
    $('#contact-form #submit').click(function () {
    
                    //Get the data from all the fields
                    var name = $('input[name=name]');
                    var email = $('input[name=email]');
                    var website = $('input[name=url]');
                    var message = $('textarea[name=message]');
    
                    //Simple validation to make sure user entered something
                    //If error found, add hightlight class to the text field
                    if (name.val()=='') {
                        name.addClass('hightlight');
                        return false;
                    } else name.removeClass('hightlight');
    
                    if (email.val()=='') {
                        email.addClass('hightlight');
                        return false;
                    } else email.removeClass('hightlight');
    
                    if (message.val()=='') {
                        message.addClass('hightlight');
                        return false;
                    } else message.removeClass('hightlight');
    
                });
    How can I use a regular expression to check for a valid email?

    Sorry, I'm really new at this.

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,336
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Select from any of these solutions.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    solved


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •