$('.global-submit').click(function(e){
// Declare the function variables:
// Parent form, form URL, email regex and the error HTML
var $formId = $(this).parents('form');
var formAction = $formId.attr('action');
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var urlReg = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;
var $error = $('<span class="form-error"></span>');
var isnum = /^\d+$/;
// Prepare the form for validation - remove previous errors
$('li',$formId).removeClass('form-error');
$('span.form-error').remove();
// Validate all inputs with the class "required"
$('.required',$formId).each(function(){
var inputVal = $(this).val();
var $parentTag = $(this).parent();
if( inputVal == '' ){
if($(this).is('#password') == true){
$parentTag.addClass('form-error').append($error.clone().text('Required Field'));
}
else if($(this).is('#confirm') == true){
$parentTag.addClass('form-error').append($error.clone().text('Required Field'));
//$('span.form-error').css('visibility', 'hidden');
}
else {
$parentTag.addClass('form-error').append($error.clone().text('Required Field'));
}
}
// Run the email validation using the regex for those input items also having class "email"
if($(this).hasClass('email') == true){
if(!emailReg.test(inputVal)){
$parentTag.addClass('form-error').append($error.clone().text('Enter valid email'));
}
}
// Run the email validation using the regex for those input items also having class "email"
if($(this).hasClass('url') == true && inputVal != ''){
if(!urlReg.test(inputVal)){
$parentTag.addClass('form-error').append($error.clone().text('Enter valid URL'));
}
}
// Run the email validation using the regex for those input items also having class...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.