473,395 Members | 1,676 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

Hi

I am working on getting my email form validated. The user has to write an email containing "@", ".", "dk or com or org or net", but I cant get it to work.

I am using the strstr function and I understand that writing only "dk" well not work.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. if (strstr($email, "@") && strstr($email, ".") && strstr($email, "dk"))
  4.  
  5.  
Apr 25 '10 #1

✓ answered by Atli

Hey.

To do something like that, you would be better of using a regular expression. They are kind of tough to learn, but well worth it.

For example, this should validate *most* email addresses coming from .net, .com or .dk domains.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $regexp = '#^[A-Z0-9._%+\-]+@[A-Z0-9.\-]+\.(net|com|dk)$#i';
  3. $email = $_POST['email'];
  4. if(preg_match($regexp, $email)) {
  5.     echo "Valid!";
  6. }
  7. else {
  8.     echo "Invalid!";
  9. }
  10. ?>
That regular expression (excluding the modification that allows only the three domains) comes from the regular-expressions.info site, which is one of the better resources on regular expressions out there. (They also have a nice tutorial, if you are interested.)

2 1512
Atli
5,058 Expert 4TB
Hey.

To do something like that, you would be better of using a regular expression. They are kind of tough to learn, but well worth it.

For example, this should validate *most* email addresses coming from .net, .com or .dk domains.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $regexp = '#^[A-Z0-9._%+\-]+@[A-Z0-9.\-]+\.(net|com|dk)$#i';
  3. $email = $_POST['email'];
  4. if(preg_match($regexp, $email)) {
  5.     echo "Valid!";
  6. }
  7. else {
  8.     echo "Invalid!";
  9. }
  10. ?>
That regular expression (excluding the modification that allows only the three domains) comes from the regular-expressions.info site, which is one of the better resources on regular expressions out there. (They also have a nice tutorial, if you are interested.)
Apr 25 '10 #2
Hi Atli

Thanks for the help;) That work just fine
Apr 25 '10 #3

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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.