Geoffrey Weed
Geoffrey Weed

Reputation: 11

Parsley.js Validation Requirement

Good afternoon all! I am looking for some guidance to see if this type of validation is possible. I work for a college and am using a form that pushes to our CRM when complete. I am looking for parsley to only validate the email address field IF they enter their college email address. Is this possible? I am trying to weave out personal email accounts and keep everything uniform with the same email address.

Thanks in advance!

Upvotes: 1

Views: 453

Answers (1)

lucash
lucash

Reputation: 2062

You can do that e.g. by using data-parsley-pattern and defining a pattern that matches only the required mail addresses. The pattern to validate against the mail addresses you mentioned in your comment might look like this:

.*@(mail\.)?walshcollege.edu$

This matches everything that:

  • Starts with any number (*) of arbitrary characters (.)
  • Followed by an @
  • Might be followed by "mail.". The dot is escaped to avoid the special meaning "any character", the question mark means "might be there or not" and the parentheses make the question apply to the complete string.
  • Ends with walscollege.edu (the $ means the end of the string)

If you also want to make sure that an mail address is inserted you need to add data-parsley-required as Parsley by default does not validate empty fields.

Also keep in mind that Parsley validation is only client side, so you should add validations in the server to really make sure that no wrong mail address is used.

Upvotes: 1

Related Questions