Skip to content

Instantly share code, notes, and snippets.

@spsaucier
Created July 20, 2013 05:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spsaucier/6044023 to your computer and use it in GitHub Desktop.
Save spsaucier/6044023 to your computer and use it in GitHub Desktop.
jQuery - Form Validation without PHP
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;
}
});
});
@dsebao
Copy link

dsebao commented Jun 12, 2015

Very usefull! thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment