Created
July 20, 2013 05:52
-
-
Save spsaucier/6044023 to your computer and use it in GitHub Desktop.
jQuery - Form Validation without PHP
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
jQuery(document).ready(function(){ | |
function randomgen() | |
{ | |
var rannumber=''; | |
for(ranNum=1; ranNum<=6; ranNum++){ | |
rannumber+=Math.floor(Math.random()*10).toString(); | |
} | |
$('#verifyNum').html(rannumber); | |
$('#verifyNumHidden').val(rannumber); | |
} | |
randomgen(); | |
//Verification number generate code Ends here | |
//Validation Starts Here | |
$('#MyForm').submit(function() { | |
if($('#enterVerify').val() == $('#verifyNumHidden').val() ) { | |
$('form').attr('action', 'https://example.com/MyForm'); | |
return true; | |
} | |
else | |
{ | |
alert("Please Enter Correct Verification Number"); | |
randomgen(); | |
$('#enterVerify').select(); | |
$('#enterVerify').focus(); | |
return false; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very usefull! thx