Last active
October 11, 2015 14:28
-
-
Save tborychowski/3872620 to your computer and use it in GitHub Desktop.
JS :: Simple form validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validate(f,v,a,x){ | |
for(a=0;x=f[a++];) | |
if((v=window[x.getAttribute('valid')])&&!v(x.value)){ | |
alert(x.getAttribute('alert')); | |
return !x.focus(); | |
} | |
} | |
function notempty(x){return x>''} | |
function ismail(e){return /^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(e)} | |
// <form onsubmit="return validate()"> | |
// <input valid="notempty" alert="enter name!" type="text" name="name"> | |
// <input valid="isemail" alert="enter email!" type="text" name="email"> | |
// </form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment