0

I am trying to allow the login input to be either username & password or email & password. How do I use the javascript function to tell whether the input is a username or an email? I am using vanilla js so no jquery or PHP, thanks!

vanilla js

dolphin
  • 1
  • 1
  • 1
    Does this answer your question? [How to validate an email address in JavaScript](https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript) – blex Feb 01 '20 at 14:41
  • Use string validation to check if the user login input is email or not, this is all what I can suggest since you didn't provide code. – ROOT Feb 01 '20 at 14:43

1 Answers1

2

Call this function on submit

function validate() {
        var login = document.getElementById('field').value;

        // Check if email
        if (/\@/.test(login)) {
           //its email address 
           // your code goes here
        }
        else {
            //its username 
           // your code goes here
        }
}
Vishnu Shenoy
  • 862
  • 5
  • 18