Email validation error inside INPUT FIELD and colour change onfocus and on error

If email is invalid, it shows message inside input field, in RED and goes back to normal colour upon click/FOCUS

<form id=”sub” name=”sub” method=”POST” action=”test.php”>

<input type=”text” name=”email” value=”Email address” onclick=”this.value=”;this.style.color = ‘#1C81A6′” style=”width:220px; height:19px;  font-size:12px; color:#1C81A6; border:1px solid #8F8D8D;”/>
<input type=”Submit” value=”” name=”Submitx”>

</form>

<?php

$emailx = $_REQUEST[’email’];

if( isset($_POST[‘Submitx’]))
{

$result=(eregi(“^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$”, $emailx));

if(!$result)
{
echo “<script>
document.forms[‘sub’].email.value = ‘INVALID’;
document.forms[‘sub’].email.style.color = ‘red’;
</script>”;
}
else
{
echo ‘true’;
}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s