Skip to content

Instantly share code, notes, and snippets.

@spsaucier
Created July 20, 2013 05:52
Show Gist options
  • Select an option

  • Save spsaucier/6044023 to your computer and use it in GitHub Desktop.

Select an option

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

dsebao commented Jun 12, 2015

Copy link
Copy Markdown

Very usefull! thx

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