Email validation help needed

Hi, I am pretty new in PHP, I would like to integrate validate function in my code.

I got the code from the internet and copied it into my code, but somehow it doesn’t work on me. Can someone enlighten me ?

Here it goes the code,I copied it into my register.php

==========================================================

After that i have this email_validation.php with this :

<?PHP header("Content-Type: text/html; charset=UTF-8"); // Your PHP Function class Validation { private $EmailTester; public function __construct(){ $this->EmailTester = '/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/'; } public function validateEmail($email){ $test = preg_match($this->EmailTester, $email); return $test; } } $ajax = new PHPLiveX(); $myClass = new Validation(); $ajax->AjaxifyObjectMethods(array("myClass" => array("validateEmail"))); // If validateEmail was a static function, you wouldn't need to create an object: // $ajax->AjaxifyClassMethods(array("Validation" => array("validateEmail"))); $ajax->Run(); // Must be called inside the 'html' or 'body' tags ?>

======================================================

Your friendly advice would be highly appreciated.

Regards,
Matt
+6012-5151070

Hmmm… Well, normally in a validation script or PHP code, there is a HTML form that call it. Do you have one to show us so we can understand your PHP and JavaScript you showed?

Also, since you mentioned you were new to PHP, make sure you understand mixing Java with PHP.
PHP runs totally SERVER-SIDE and Java runs CLIENT-SIDE. All PHP code runs on the server and is then
mixed with HTML and SERVED to the browser where Javascript runs. Most PHP validation is handled by
a page POSTing to a .PHP page that reads all the $_POST variables and handles validation.

JAVASCRIPT validation is handled after the PHP and HTML has joined and been served to the browser.
This is usually handled in a function that scans the input areas in the document (which means webpage)
and compares them with all your “rules”. The javascript you show is this type.

Soooo, if I haven’t mixed you up completely. First you need some regular HTML code to create your form.
Then, pick a way to validate it. I prefer true PHP, in which you just post to a second .php page from the
original form.html page. It would read the $_POST[] variables and compare them using your ‘rules’.
If they don’t pass your rules, the user is redirected to a page stating the errors and back button to try
again. But, if you wish Javascript validation, use the first code you posted and use the click option on your SUBMIT button on the form. ( ONCLICK=“validate();” )

Here is a link to a short sample of email form with some validation. It might help you a little further:
http://www.html-form-guide.com/contact-form/php-email-contact-form.html

Good luck and post any further questions…

Sponsor our Newsletter | Privacy Policy | Terms of Service