Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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