简体   繁体   中英

Different validation scenarios for Parsley

The project which I working on uses Parsley.js as the validation framework. I have not worked on this framework much so, I am unaware of how to show different error messages when the input is empty and when there is an invalid value entered. For example, if the user doesn't enter any value for a particular field, I want to display "This field is required." And when there is an invalid value, I want to display "Please enter a valid value for this field". This is what I have as far of now.

<input type="text" name="firstName" maxlength="40" required pattern="/^[a-zA-Z ',-]+$/" data-parsley-error-message="This field is required">

Any help is appreciated.

<input type="text" name="firstName" maxlength="40" 
    required 
    pattern="/^[a-zA-Z ',-]+$/" 
    data-parsley-required-message="This field is required."
    data-parsley-pattern-message="Please enter a valid value for this field."/>

See http://parsleyjs.org/doc/index.html#ui-for-field for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM