Jump to content

[SOLVED] Validating characters in URLs, e-mails and ages.


DavidGS

Recommended Posts

OK, so I need a code to validate that a user's e-mail address, URL and age entered into a form is valid (syntax). I have the form set up and it works and writes information to a database. It checks that a URL entered isn't already in a database and same with the e-mail. All I want it to do now is check that that  the e-mail address entered is in the correct format, to check if the URL entered only contains letters, numbers and underscores and the age entered is actually a number. For the e-mail validation, it should accept e-mail addresses from top-level domains other than .com (like .co.uk and .com.au), the URL validation should accept letters numbers and underscores and the age validation should only accept two-digit numbers (any zeros at the start eliminated). Any help would be appreciated.

Link to comment
Share on other sites

Hm, when I use this code to check if e-mails entered are valid, It always returns the same value, even if the e-mail isn't valid.

 

if (!eregi("\b[A-Z0-9_%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b",$emailused)) {$validemail = 1;} else {$validemail = 0;}

 

I just can't figure out why.

Link to comment
Share on other sites

n~ link=topic=174027.msg770040#msg770040 date=1198494359]

See this,

 

<?php if (preg_match('/^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i', $emailused)) {
        echo 'Email entered is valid';
} else {
        echo 'Email entered is not valid';
} ?>

 

THANKS! It works great. What would I enter if I didn't want any symbols other than a particular symbol in a string. Because I am making a website that lets you register your own personal URL (like MySpace) and I don't want to let the user enter any characters other than letters, numbers and underscores to prevent any errors with their URL.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.