473,395 Members | 1,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

email validation

Hello, im posting this question because i have zero knowledge on perl. I have a script which curently allows users to input an email address and if the email is not valid it wont allow the submission. Everything works fine except that now there are clients who have a period in their email address and it is rejected. eg. tom.jones@email.com.. im sure its a simple addition to the script not even sure where it might go but here is what i copied and where im assuming it might need to be changed..


Code: ( text )
Expand|Select|Wrap|Line Numbers
  1. # Do our error checking
  2.   my $gintErrorCount = 0;
  3.   my $gstrMessage = "";
  4.  
  5.   # Email Address
  6.   unless ($gstrHash{email} =~ m/^(\w+)\@(\w+)\.(\w{2,4})$/)  {$gintErrorCount ++; $gstrMessage .= "Your email address is not properly formatted.<BR>";}
  7.  
  8.   # Fix phone variable - client
  9.   $gstrHash{cphone} =~ s/\D//g;
  10.   unless ($gstrHash{cphone} =~ m/^\d{10}$/) {$gintErrorCount ++; $gstrMessage .= "Your contact phone number must be a ten digit number.<BR>";}
  11.   $gstrHash{cphone} =~ s/^([\d]{3}?)([\d]{3}?)([\d]{4}?)$/\($1\)$2-$3/i;   
  12.  
  13.   # Email Address
  14.   unless ($gstrHash{cemail} =~ m/^(\w+)\@(\w+)\.(\w{2,4})$/)  {$gintErrorCount ++; $gstrMessage .= "Your contact email address is not properly formatted.<BR>";}
  15.  
i appreciate any help
thanks
EMI
Sep 8 '08 #1
4 2488
numberwhun
3,509 Expert Mod 2GB
In that case, you could modify your regex to be something like:

Expand|Select|Wrap|Line Numbers
  1. m/^(\w+\.*\w*)\@(\w+)\.(\w{2,4})$/
  2.  
Mind you, that is totally untested, but in theory, I believe it should work. Test it to find out. The \.*\w* will only match if they are present.

Regards,

Jeff
Sep 8 '08 #2
eWish
971 Expert 512MB
I would suggest that you use a trusted and proven module called Email::Valid. Is it perfect? No, however it is going to be better than designing your own. Check out the source code and see the regex the author built.

If you want to do you own you could use something like this.
Expand|Select|Wrap|Line Numbers
  1. my $email =~ /^[^@]+@([-\w]+\.)+[A-Za-z]{2,4}$/;
I still suggest Email::Valid.

--Kevin
Sep 8 '08 #3
thank you guys...i think that did it..just have to try a few tests live and see how it goes.
much appreciated.
Cheers
Emi
Sep 10 '08 #4
eWish
971 Expert 512MB
What did you end up using?

--Kevin
Sep 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: Dynamo | last post by:
Hi The following script was taken from John Coggeshall's (PHP consultant) in his article on Zends site at http://www.zend.com/zend/spotlight/ev12apr.php // Get the email address to validate...
2
by: Angel | last post by:
Hi there, I need help pls..I'm using c# on a webform and I have this regex validation for email addresses: ValidationExpression ="\w+(\w+)*@\w+(\w+)*\.\w+(\w+)* " I'm having isssues when submit...
4
by: VbUser25 | last post by:
Hi Please suggest i think i am doing something wrong. I am calling fucntion test from another function where i am performing all the validations.I want to validate the email id. this is the...
2
by: Tim Mills | last post by:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a...
35
by: Mika M | last post by:
Simple question: Does Framework (1.1) contain any routine to check entered email-address is valid ? It's quite easy to make own code for that purpose, but why to do if Framework (1.1) contain...
7
by: e_matthes | last post by:
Hello everyone, I've read enough about email validation to know that the only real validation is having a user respond to a confirmation message you've sent them. However, I want to store the...
10
by: ll | last post by:
Hi, I currently am using the following regex in js for email validation, in which the email addresses can be separated by commas or semicolons. The problem, however, lies in that I can type two...
11
by: Bob Bedford | last post by:
Hi all, we have many people that have registered to our newsletter and we are getting every time more people who the email is unavailable. It's there any technique to detect such unavailable...
3
Maidenz08
by: Maidenz08 | last post by:
How do i check whether an email id exists or not? I am following a three step validation process.. 1) syntax validation- which is pretty straight forward 2) DNS validation - I'm able to do...
1
by: shwethatj | last post by:
My problem is lik this , I am trying to create a registration form using javascript for a HR website , but i dont know how to provide password validation i.e the password and confirmation password...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.