Jump to content

so i have an email validation assigment and i have tomake a simple program too validate a email so that it is

 

 

alpanumeric@alpanumeric.alpanumeric

 

this is my current abomonation

 

<head>

<title>Online Booking system</title>

Please enter your email address

<p>

<form action="valid.html">

<table width=100%" border="0">
 
<tr>
    <input type="text" name="Submit" placeholder="Enter your email address"
    pattern=^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$>
</tr>

<tr>
    <td>
        <input type="submit" value="Submit">
        <input type="reset" value="Reset ">
    <td>
</tr>

</form>

</head>

 

 

it dosnt reject if there is nithing entered

 

 

ty sorry for being  a noob : )

Link to comment
https://linustechtips.com/topic/245179-html-javascript-email-validation/
Share on other sites

Link to post
Share on other sites

For some reason, HTML doesn't validate the pattern if the input field is blank. The work around for this is to make the input "required" by adding required="required" or simply required to the input element.

<input type="text" name="Submit" placeholder="Enter your email address"    pattern=^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$ required>

You might want to play around with this: http://regexpal.com/ to improve your regex.

Currently _@-.aa is a valid email, which may not even be an issue.

Link to post
Share on other sites

<script>function validateForm() {var e = document.forms["reg"]["email"].value;    var atpos = e.indexOf("@");    var dotpos = e.lastIndexOf(".");    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=e.length) {        alert("Not a valid e-mail address");        return false;    }</script>
<form method="post" action="process.php" onsubmit="return validateForm()" name="reg"><input type="text" name="email" placeholder="your email" data-clear-btn="true"><input type="submit" value="register" name="reg"></form>

what i'm using on my site for my college project.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×