Skip to content

Instantly share code, notes, and snippets.

@swapnil-webonise
Created October 2, 2013 10:36
Show Gist options
  • Save swapnil-webonise/6791799 to your computer and use it in GitHub Desktop.
Save swapnil-webonise/6791799 to your computer and use it in GitHub Desktop.
JQuery Validation
jQuery(function()
{
//contact details validations
jQuery("#txtCurrentAddress").validate({
expression: "if ((VAL.match(/^[A-Za-z0-9,\.\ \:\-\]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Current Address"
});
jQuery("#txtCurrentAddressCity").validate({
expression: "if ((VAL.match(/^[A-Za-z \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Current Address City"
});
jQuery("#txtCurrentAddressState").validate({
expression: "if ((VAL.match(/^[A-Za-z \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Current Address State"
});
jQuery("#txtCurrentAddressPIN").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && VAL.length==6) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Current Address PIN"
});
jQuery("#txtPermnentAddress").validate({
expression: "if ((VAL.match(/^[A-Za-z0-9,\.\ \:\-\]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Permnent Address"
});
jQuery("#txtPermnentAddressPIN").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && VAL.length==6) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Permnent Address PIN"
});
jQuery("#txtGender").validate({
expression: "if ((VAL.toLowerCase().match('male') && VAL.trim().length==4) || (VAL.toLowerCase().match('female') && VAL.trim().length==6) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Gender"
});
jQuery("#txtMarritalStatus").validate({
expression: "if ((VAL.toLowerCase().match('single') && VAL.trim().length==6) || (VAL.toLowerCase().match('married') && VAL.trim().length==7) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Marrital Status"
});
jQuery("#txtDOB").validate({
expression: "if (!isValidDate(parseInt(VAL.split('-')[2]), parseInt(VAL.split('-')[0]), parseInt(VAL.split('-')[1]))) return false; else return true;",
message: "Please Enter Valid Birth Date"
});
jQuery("#txtMobileNumber").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && VAL.length==10) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Mobile Number"
});
jQuery("#txtPhoneNumber").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && VAL.length==11) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Phone Number"
});
jQuery("#txtEmailID").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}$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Email ID"
});
jQuery("#txtHobbies").validate({
expression: "if ((VAL.match(/^[A-Za-z,\.\ \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Hobbies"
});//
jQuery("#txtLanguagesKnown").validate({
expression: "if ((VAL.match(/^[A-Za-z,\.\ \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Languages"
});
jQuery("#ContactDetails").validated
( function()
{
updateContactDetails(j);
disableContactDetailsFields();
});
});
//SSC details validation
jQuery("#txtSSCOutOf").validate({
expression: "if ((VAL.match(/^[0-9]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Out Of Marks"
});
jQuery("#txtSSCMarks").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && document.getElementById('txtSSCMarks').value.trim()==VAL ) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Marks"
});
jQuery("#txtSSCMarks").validate({
expression: "var marks=document.getElementById('txtSSCMarks').value; var outOf=document.getElementById('txtSSCOutOf').value; if (marks<=outOf) return true; else return false;",
message: "Please Enter Valid Marks"
});
jQuery("#txtSSCOutOf").validate({
expression: "var marks=document.getElementById('txtSSCMarks').value; var outOf=document.getElementById('txtSSCOutOf').value; if (marks<=outOf) return true; else return false;",
message: "Please Enter Valid Out Of Marks"
});
jQuery("#txtSSCPercentage").validate({
expression: "if ((VAL.match(/^[0-9.\]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Percentage"
});
jQuery("#txtSSCYearOfPassing").validate({
expression: "if ((VAL.match(/^[0-9.\]+$/) && VAL.length==4) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Year Of Passing"
});
jQuery("#txtSSCBoard").validate({
expression: "if ((VAL.match(/^[a-zA-Z \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid SSC Board"
});
jQuery("#txtSSCSchoolName").validate({
expression: "if ((VAL.match(/^[0-9a-zA-Z.\,\ \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid SSC School Name"
});
jQuery("#SSCDetails").validated
( function()
{
updateSSCDetails(j);
disableSSCDetailsFields();
});
//HSC details validation
jQuery("#txtHSCStream").validate({
expression: "if ((VAL.match(/^[a-zA-Z \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid HSC Stream"
});
jQuery("#txtHSCMark").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && document.getElementById('txtHSCMark').value.trim()==VAL) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Marks"
});
jQuery("#txtHSCOutOf").validate({
expression: "if ((VAL.match(/^[0-9]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Out Of Marks"
});
jQuery("#txtHSCMark").validate({
expression: "var marks=document.getElementById('txtHSCMark').value; var outOf=document.getElementById('txtHSCOutOf').value; if (marks<=outOf) return true; else return false;",
message: "Please Enter Valid Marks"
});
jQuery("#txtHSCOutOf").validate({
expression: "var marks=document.getElementById('txtHSCMark').value; var outOf=document.getElementById('txtHSCOutOf').value; if (marks<=outOf) return true; else return false;",
message: "Please Enter Valid Out Of Marks"
});
jQuery("#txtHSCPercentage").validate({
expression: "if ((VAL.match(/^[0-9.\]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Percentage"
});
jQuery("#txtHSCYearOfPassing").validate({
expression: "if ((VAL.match(/^[0-9.\]+$/) && VAL.length==4) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Year Of Passing"
});
jQuery("#txtHSCBoard").validate({
expression: "if ((VAL.match(/^[a-zA-Z \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid SSC Board"
});
jQuery("#txtHSCSchoolName").validate({
expression: "if ((VAL.match(/^[0-9a-zA-Z.\,\ \]+$/)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid SSC School Name"
});
jQuery("#HSCDetails").validated
( function()
{
updateHSCDetails(j);
disableHSCDetailsFields();
});
});
jQuery(function()
{
jQuery("#txtDegreeName").validate({
expression: "if (VAL.match(/^[a-zA-Z0-9 \.\+\]+$/) || VAL.length==0) return true; else return false;",
message: " Valid Degree Name"
});
jQuery("#txtGrade").validate({
expression: "if ((VAL.match(/^[a-zA-Z+\]+$/) && (VAL.length<=2)) || VAL.length==0) return true; else return false;",
message: "Enter Valid Grade"
});
jQuery("#DegreeDetails").validated(
function()
{
updateStudentDegreeDetails(1);
});
});
jQuery(function()
{
//student certificate details
jQuery("#txtCerificate").validate({
expression: "if (VAL.match(/^[a-zA-Z0-9 \.\+\]+$/) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Certificate Name"
});
jQuery("#txtGrade").validate({
expression: "if ((VAL.match(/^[a-zA-Z+\]+$/) && (VAL.length<=2)) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Grade"
});
jQuery("#CertificationDetails").validated(
function()
{
updateStudentCertificateDetails(j);
});
});
jQuery(function()
{
jQuery("#txtProjectsName").validate({
expression: "if (VAL.match(/^[a-zA-Z \.\]+$/) || VAL) return true; else return false;",
message: "Enter Project name"
});
jQuery("#txtTechnology").validate({
expression: "if (VAL) return true; else return false;",
message: "Enter Technology name"
});
jQuery("#txtremark").validate({
expression: "if (VAL) return true; else return false;",
message: "Please Enter Remark"
});
jQuery("#addProjectForm").validated(
function()
{
updateStudentProjectDetails(j);
});
});
jQuery(function()
{
//Work experience details
jQuery("#txtOrganizationName").validate({
expression: "if (VAL.match(/^[a-zA-Z \.\]+$/) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Organization name"
});
jQuery("#txtServicePeriod").validate({
expression: "if ((VAL.match(/^[0-9]+$/) && (VAL < 50)) || VAL.length==0) return true; else return false;",
message: "Please Enter Service exprience"
});
jQuery("#WorkExperienceDetails").validated(
function()
{
updateWorkExprienceDetails(j);
});
});
jQuery(function()
{
//Technical specification details
jQuery("#txtTechnicalSpecification").validate({
expression: "if (VAL.match(/^[a-zA-Z \]+$/) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Technical Specification"
});
jQuery("#txtTechnologyName").validate({
expression: "if (VAL.match(/^[a-zA-Z0-9.\#\+\ \]+$/) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Technology Name"
});
jQuery("#txtProficiency").validate({
expression: "if(VAL.match(/^[1-9]+$/) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Proficiency"
});
jQuery("#TechnicalSpecification").validated(
function()
{
updateTechnicalSpecificationDetails(j);
});
});
jQuery(function()
{
//Gap specification details
jQuery("#txtFromYear").validate({
expression: "if ((VAL.match(/^[0-9.\]+$/) && VAL.length==4) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Year"
});
jQuery("#txtToYear").validate({
expression: "if ((VAL.match(/^[0-9.\]+$/) && VAL.length==4) || VAL.length==0) return true; else return false;",
message: "Please Enter Valid Year"
});
jQuery("#txtFromYear").validate({
expression: "var from=document.getElementById('txtFromYear').value; var to=document.getElementById('txtToYear').value; if (from <= to) return true; else return false;",
message: "Please Enter Valid Year"
});
jQuery("#txtToYear").validate({
expression: "var from=document.getElementById('txtFromYear').value; var to=document.getElementById('txtToYear').value; if (from <= to) return true; else return false;",
message: "Please Enter Valid Year"
});
jQuery("#txtReason").validate({
expression: "if(VAL) return true; else return false;",
message: "Please Enter Reason"
});
jQuery("#GapSpecification").validated(
function()
{
updateGapSpecificationDetails(j);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment