very simple preg_match for email validation question

alright, so I got this function from a friend
[php]function ValidEmail($email) {//checks if the email is in a valid foramat
return preg_match("/^([\w!#$%&’*+-/=?^`{|}~]+.)*[\w!#$%&’*+-/=?^`{|}~][email protected]((((([a-z0-9]{1}[a-z0-9-]{0,62}[a-z0-9]{1})|[a-z]).)+[a-z]{2,6})|(\d{1,3}.){3}\d{1,3}(:\d{1,5})?)$/i",trim($email));
}[/php]
it basically checks if the email was typed correctly.
how would I call this and verify it inside my registration page. I know how to use functions, but I don’t know how preg_match works.

that function is a php function. it can be executed only at the server (which needs form submit). You dont want to submit the registration form if the data is not valid. it means, u have to validate the email id at the client side itself before actually submitting the page. it can be done thru javascript functions. i give u a javascript function that can be used to validate the email id at the client end

<script language="javascript">
// this function should be called from onclick event of register button
function validateForm() 
{      
        str = document.getElementById(control).value; // replace control with the id of email id text box
	var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if(!(str.match(emailRegEx))) { alert('Email-Id is not valid'); return false; }

       // place other validation rules here if u want

       document.forms['regform'].submit(); 
      // here u r manually submitting the form if all the validations are ok. you can change 'regform' with ur form id
}

register button example

Sponsor our Newsletter | Privacy Policy | Terms of Service