JSFiddle - React, Tailwind, and code Playground
HTML
<script>
jQuery(function(){
jQuery("#ValidField").validate({
expression: "if (VAL) return true; else return false;",
message: "Please enter the Required field"
});
jQuery("#ValidNumber").validate({
expression: "if (!isNaN(VAL) && VAL) return true; else return false;",
message: "Please enter a valid number"
});
jQuery("#ValidInteger").validate({
expression: "if (VAL.match(/^[0-9]*$/) && VAL) return true; else return false;",
message: "Please enter a valid integer"
});
jQuery("#ValidEmail").validate({
expression: "if (VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;",
message: "Bitte geben Sie eine gĂĽltige e-Mail Adresse an"
});
jQuery("#ValidPassword").validate({
expression: "if (VAL.length > 5 && VAL) return true; else return false;",
message: "Geben Sie ein mindest 6-stelliges Passwort ein"
});
jQuery("#ValidConfirmPassword").validate({
expression: "if ((VAL == jQuery('#ValidPassword').val()) && VAL) return true; else return false;",
message: "Passworteingabe nicht identisch"
});
});
/* ]]> */
</script>
<div><form action="" method="post" class="AdvancedForm">
<div><div class="a"><label for="ValidEmail">Enter Email ID:</label></div><div
class="b"><input type="text" name="ValidEmail" id="ValidEmail" /></div></div>
<div><div class="a"><label for="ValidPassword">Password:</label></div><div
class="b"><input type="password" name="ValidPassword" id="ValidPassword" /></div></div>
<div><div...
CSS
* {font:normal 15px "consolas"}
.AdvancedForm {width:900px; padding:25px 20px 15px 20px; background:#fff}
.a, .b {display:inline-block; padding-bottom:5px}
.a {width:180px; text-align:right; padding-right:10px}
.b {width:700px}
input[type=text],
input[type=password] {width:300px; padding-left:2px; height:21px}
input[type=password] {letter-spacing:2px; color:#333}
input[type=submit] {margin-left:190px}
span {margin-left:10px; padding:2px 4px; border:2px solid #94423c; position:relative; bottom:1px}
JavaScript
/**
* @author GeekTantra
* @date 24 September 2009
*/
/*
* This functions checks where an entered date is valid or not.
* It also works for leap year feb 29ths.
* @year: The Year entered in a date
* @month: The Month entered in a date
* @day: The Day entered in a date
*/
function isValidDate(year, month, day){
var date = new Date(year, (month - 1), day);
var DateYear = date.getFullYear();
var DateMonth = date.getMonth();
var DateDay = date.getDate();
if (DateYear == year && DateMonth == (month - 1) && DateDay == day)
return true;
else
return false;
}
/*
* This function checks if there is at-least one element checked in a group of check-boxes or radio buttons.
* @id: The ID of the check-box or radio-button group
*/
function isChecked(id){
var ReturnVal = false;
$("#" + id).find('input[type="radio"]').each(function(){
if ($(this).is(":checked"))
ReturnVal = true;
});
$("#" + id).find('input[type="checkbox"]').each(function(){
if ($(this).is(":checked"))
ReturnVal = true;
});
return ReturnVal;
}
/**
* @author GeekTantra
* @date 20 September 2009
*/
(function(jQuery){
var ValidationErrors = new Array();
jQuery.fn.validate = function(options){
options = jQuery.extend({
expression: "return true;",
message: "",
error_class: "ValidationErrors",
error_field_class: "ErrorField",
live: true
}, options);
var SelfID = jQuery(this).attr("id");
var unix_time = new Date();
unix_time = parseInt(unix_time.getTime() / 1000);
if (!jQuery(this).parents('form:first').attr("id")) {
jQuery(this).parents('form:first').attr("id", "Form_" + unix_time);
}
var FormID = jQuery(this).parents('form:first').attr("id");
if (!((typeof(ValidationErrors[FormID]) == 'object') && (ValidationErrors[FormID] instanceof Array))) {
...