Results 1 to 2 of 2

Thread: How to test RegExp

  1. #1
    Join Date
    Apr 2008

    How to test RegExp

    			function testemail(){
    			var fld= document.getElementById("input1").value;
    			var reg = /^[\w+]@[\w+].com$/i;
    				alert("email is ok");
    				alert("email is not correct");
    			<form name="form1" onsubmit="testemail()">
    				enter email : <input id="input1" type="text" /> <input id="input2" type="submit" value="Submit" />
    I am trying to test an email ID with above RegExp. I enter a correct email or not, I am always getting message "email is not correct" So RegExp is not working. How can I find out whats wrong with this RegExp ? Is there any tool to figure that out ? I tried with FireBug, but it does not point to whats wrong with RegExp


  2. #2
    Join Date
    Oct 2010
    Versailles, France
    Test at first something like this :
    var reg = /^[\w.+-]+@[\w.]+\.com$/i;
    With + quantifiers outside the square brackets to allows one or more characters for each class. A back slash is useful to escape the point outside the brackets (I add two points inside the classes but there is other characters to add).

    There is many regular expressions (like this according to the RFC 822 grammar for perl) to test email addresses...

    For practical use, see this page which give good reasons to take this kind of validation with precautions...

    The best test for validation consists to send an email for confirmation !

    nb : There is many regular expressions tester on the web (like this one)
    Last edited by 007Julien; 04-19-2012 at 08:01 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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