Email/Number Validation

Discussion in 'PHP' started by technoguy, Feb 5, 2007.

Thread Status:
Not open for further replies.
  1. #1
    How to validate textbox for numbers and email using php (not java script) can anyone help me plz? And yes it is possible to see if first character of text box should be alphabet using php?

    Thank you
     
    technoguy, Feb 5, 2007 IP
  2. sharpweb

    sharpweb Guest

    Messages:
    246
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check for digits (0-9) only:

    function checkDigits($element) {
    		if(strlen ($element) > 0) {
    	  		return !preg_match ("/[^0-9]/", $element);
    		}
    		return false;
    	}
    Code (markup):
    Check for a valid email address:

    
    	function checkEmail($email) {
    	  $pattern = "/^[A-z0-9\._-]+"
    			 . "@"
    			 . "[A-z0-9][A-z0-9-]*"
    			 . "(\.[A-z0-9_-]+)*"
    			 . "\.([A-z]{2,6})$/";
    	  return preg_match ($pattern, $email);
    	}
    Code (markup):
    I don't have one handy for first character of text has to be alphabet and I've got to run, but those two should help out.
     
    sharpweb, Feb 5, 2007 IP
  3. alfredn

    alfredn Peon

    Messages:
    1,198
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, this helped me a bunch as well.
     
    alfredn, Feb 6, 2007 IP
Thread Status:
Not open for further replies.