-2

I am working on a PHP file where password and email has to have a requirement for their files. Requirements I am doing in a separate document.

So far for my password I have this set up in register.php ->

<div class="tRow>
                <div class="tCell"><label for="txtpassword">Password:</label></div>
                <div class="tCell">
                <input type="password" id="txtpassword" name="Password"/>
                </div>
            </div><!-- END OF THIS SELECTION -->`

When user clicks Submit Button -> div class="tRow"> <div class="tCell"><input type="submit" id="submit_button" value="Sumbit" onclick="CheckLength('txtpassword')" /></div> </div><!--END OF THIS SELECTION-->

I am currently doing the same for email.

<div class="tRow> <div class="tCell"><label for="user_email">E-mail:</label></div> <div class="tCell"> <input type="text" id="user_email" name="E-mail"/> </div> </div><!-- END OF THIS SELECTION -->

Any suggestions on how to add the requirement for the email?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Sozo Teki
  • 1
  • 2

2 Answers2

0

You can add another event to the onclick - something like this:

<input type="submit" id="submit_button" value="Sumbit" onclick="CheckLength('txtpassword'); checkemail('user_email')" />

Then you would have to write a javascript function to handle the email validation, something like:

function validateEmail(email) {
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(String(email).toLowerCase());
    }

(From How to validate an email address in JavaScript?)

arsis-dev
  • 413
  • 1
  • 4
  • 14
  • Seems like I had something different when i was doing the validation for password. Thank you for showing me this. – Sozo Teki Apr 25 '18 at 13:50
0

There are two solutions to check the email using what languages ​​provide us natively.

First, HTML5 introduces a new input type: email
Check the documentation: MDN Web Docs | Email input

Invalid input example: é@ç
Valid input example : -@_ , e@n

<input type="email" id="user_email" name="E-mail" />" 

Secondly, with PHP, you can use validate filters to check if the value submitted is an email
Check the documentation: PHP Docs | Validate filters

<?php
$email = "john.doe@example.com";

if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
  echo("$email is a valid email address");
} else {
  echo("$email is not a valid email address");
}
?>

If you want to use JavaScript to check your value, read this response on another Stackoverflow question:
How to validate an email address in JavaScript?

Hoping it helps you ;)

TiTnOuK
  • 174
  • 1
  • 9