-1

I am using http://jqueryvalidation.org/. And I want to add a rule to validate the field from the value entered by users on fourth letter.

Like if value is = ABCPUJJE

and we set rule that fourth letter = P

then the rule will check fourth value and display message "Right value entered" else "Please Enter correct value"

  • You should have made an honest attempt at this yourself before asking for help. – Sparky Mar 14 '14 at 20:34
  • possible duplicate of [jQuery Validate Plugin - How to create a simple, custom rule?](http://stackoverflow.com/questions/241145/jquery-validate-plugin-how-to-create-a-simple-custom-rule) – Sparky Mar 14 '14 at 20:38
  • I am a designer and did know nuch abou jquery so i asked! – user3421366 Mar 20 '14 at 07:03

1 Answers1

0

Defining custom method

function myTextOnlyValidation(value, element){

   var fourthChar = value.charAt(3);

   if (fourthChar === 'P') {
     return true;
   } else {
     return false;
   }
}

Add custom method to jquery validator

jQuery.validator.addMethod("validateChar", myTextOnlyValidation, "Custom Message");

Adding validation to the element

$('#TestForm').validate({
  rules : {
     txtboxElement: { validateChar: true }
  }
});
Arjit
  • 3,290
  • 1
  • 17
  • 18