Jump to content

input type email


BluwAngel

Recommended Posts

so i have field for email

 

<input id="email" name="email" type="email" /><br />

 

is there and HTML command to prevent it from leaving blank (if you type "test" it will say its not email. any way to do that if some leave it blank?)

 

i created filter with JS, but i want same that bubble box where it say "please enter email or something like that

Link to comment
https://forums.phpfreaks.com/topic/260149-input-type-email/
Share on other sites

use this...

 

 

javascript code

<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert("Not a valid e-mail address");
  return false;
  }
}
</script>

 

 

 

this is html code....

 

<form name="myForm" action="demo_form.asp" onsubmit="return validateForm();" method="post">
Email: <input type="text" name="email">
<input type="submit" value="Submit">
</form>

Link to comment
https://forums.phpfreaks.com/topic/260149-input-type-email/#findComment-1336004
Share on other sites

The "email" type attribute will actually validate the data it contains if you set the "required" attribute.

 

Of course, not all browsers yet support this functionality however.

 

I actually forgot that it validates it's contents if required.

Here is the regex that it uses for validation:

 

/^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/

 

not the tightest regex, but efficient enough.

 

and the w3 docs if anyone cares to see: http://dev.w3.org/html5/markup/input.email.html

 

but yah as noted, not all browsers yet support this and server side validation is still required.

Link to comment
https://forums.phpfreaks.com/topic/260149-input-type-email/#findComment-1336045
Share on other sites

use this in php

 

$email( is a variable contain value of email field)

 

if(!$email == "" && (!strstr($email,"@") || !strstr($email,".")))

{

echo "<h2>Use Back - Enter valid e-mail</h2>\n";

$badinput = "<h2> NOT submitted</h2>\n";

echo $badinput;

}

 

this is a poor check, just use filter_var with the FILTER_VALIDATE_EMAIL flag.

Link to comment
https://forums.phpfreaks.com/topic/260149-input-type-email/#findComment-1336057
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.