I’m looking Jquery UI’s modal form demo. But i want to add something.
This demo checking all inputs’ (name,email,password) lenght and validate them. But email input must be optional. Because of this i’m setting email input’s min value (for checkLength() function) to zero. But when i leave blank email input i’m getting validation error. You can check full codes here .
It’s validation email with this code :
bValid = bValid && checkRegexp( email, ..SOME REGEX PATTERNS WILL COME HERE.., "eg. ui@jquery.com" );
But i want to try validation only if there is any email input. Because email input is optional and visitors can leave it. How can i add if statement (if email input is filled, validate it. Else don’t try validation) to this code ?
I hope it’s clear.
If you are saying “how to do validation only if email is not empty?”, then I see no reason this wouldn’t work:
Note: if you actually have no idea how to use conditional statements in JS, you may have a lot of hurdles ahead of you. See this for a quick reference, and/or get a book about JS basics.