Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m validating email address when user register and login.
One user was not able to register cause of his email address was in this format:

example@so-lutions.co.za

Maybe the problem is on my expression of validating.

My code:

HTML
HTML
<div class="warn"> <input type="email" name="email" id="email" placeholder="Email" required="required"<?php getpostvalue('email'); ?>/> </div><pre lang="HTML">


JavaScript
JavaScript
<pre lang="xml"><script type="text/javascript">

jQuery(function(){
jQuery("#email").validate({

expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
                    message: "<br>Please provide a valid email address!!</b>"

                });
            });

</script>




Your help will be appreciated.
Posted

You're not including hyphen characters in the domain name section of your reg-ex. Suggest the following to include them:

/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_\\-]+(\\.[a-zA-Z0-9_\\-]+)*\\.[a-zA-Z]{2,4}$/
 
Share this answer
 
v2
I have find a solution to my problem by changing my expression to this:


JavaScript
<pre lang="xml"><script type="text/javascript">
            jQuery(function(){
                jQuery("#email").validate({

                    expression: "if (VAL.match(/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)) return true; else return false;",
                    message: "<br>Please provide a valid email address!!</b>"

                });
            });

</script>

 
Share this answer
 
Have a look here at How to Find or Validate an Email Address[^]. It should give you input to solve your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900