Create custom validator to check if the input is a string in Parsley

parsley custom validator
parsley-validate on submit
parsley date validation
parsley-validate single field
parsley js example
parsley-validate phone number
data-parsley-pattern-message
parsley ajax validation example

I want to create a custom validator that check if the input is a string and not a number. Example: I enter 2 in the input it should display the error message and it will be triggered when I put data-parsley-name

<script type="text/javascript" src="js/jquery-3.4.1.js"></script>
<script type="text/javascript" src="js/parsley.min.js"></script>

<input type="text" id="f_name" name="f_name" placeholder="Enter First Name" data-parsley-required="true" data-parsley-trigger=" focusout" data-parsley-name>
window.Parsley.addValidator('name', {
        requirementType: 'string',
        validateString: function(value) {
            if(isNaN(value)){
                return value;
            }
        },
        messages: {
          en: 'Enter a Valid Name',

        }
      });

I found out I can use data-parsley-pattern="^[a-zA-Z]+$"

Custom validator - Parsley, This is a handy way to configure all your form's inputs in a row by passing their config Useful if you need some custom validators that check something particular when a field is empty. Validates that the length of a string is at least as long as the given limit. That's why Parsley lets you easily create your own validators. I want to add a custom validator to parsley.js. It should test if the specific field contains only letters. I tried to use the regexp validator but then i cant use custom errors cause i need the re

Use jQuery's .isNumeric() https://api.jquery.com/jQuery.isNumeric/

    validateString: function(value) {
        if($.isNumeric(value) == false){
            return value;
        }
    }

The ultimate documentation, parsleyjs is the Parsley form validator. <form data-parsley-validate> <! data-​parsley-mincheck='1' data-parsley-maxcheck='3' data-parsley-check='[1, 3]' element.closest('.input-group') if ($parent.length) return $parent return field.$​element addValidator('multipleOf', { // string | number | integer | date | regexp | boolean  Create custom validator to check if the input is a string in Parsley. I want to create a custom validator that check if the input is a string and not a number

In your validator function change this:

validateString: function(value) {
        if(value === "" + value){
            return value;
            console.log(this.messages.en);
        }
    }

But if you want to validate numbers use this code: if(Number(value) === value);.

Number(value) is turning your value to the number. And if it is equal to your input it will return it and print the message.

Parsley.js cheatsheet, But here we will make Parsley.js custom validation for check particular email is required Duration: 12:17 Posted: Nov 13, 2019 oh my god excuse my ignorance, i did not see it, thanks a lot this is awesome, but is it possible to improve the API so there wont be need to clutter the code with to many data-attribute like i mentioned above, it is more elegant. plus is there ability to pass string.format tokens like i mentioned above ? this will make it super

Parsley.js Custom Validator for Email Availability with PHP , A validator is a method to determine if a given value (or sometimes sets of values​) is acceptable or not, That's why Parsley lets you easily create your own validators. validateString, Is passed the input's value as a string. The built in angular required input is easily fooled by a run of spaces so lets create our own validator. I read the Angular.io Custom Validator docs for you. We can use this rather simple idea to demonstrate a validator with unit testing, wrapped in a simple directive. Jump to the code: no-whitespace.validator.ts; no-whitespace.validator.specs.ts

parsley validation, Parsley 2.8.1 jQuery 3.x I believe this is a bug, either in code or documentation. I'​m wiring up a custom validator, to validate a simple form: Note the data-parsley​-foobar="100" attribute on the text input field. However, when invoked, my validateString function is passed a requirement of type number :. There are many ways of carrying out input validation in Node.js. For simplicity purposes, we will consider validatorJS — a validation library inspired by the Laravel framework’s validator. In this tutorial, we will learn how to handle data validation in Node using validatorJS. Prerequisites. This tutorial uses the following: Basic knowledge

Custom validator passed a number with requirementType: 'string , Parsley is a dead simple javascript form validation, powerful and UX aware. by default does not proceed with field validation when less than 3 chars have been input. parsley-remote-datatype="jsonp" if you make cross domain ajax call and expect jsonp It allows you to add another custom check on top of Parsley. To create a server-side validation function, provide a handler for the ServerValidate event that performs the validation. The string from the input control to validate can be accessed by using the Value property of the ServerValidateEventArgs object passed into the event handler as a parameter.

Comments
  • Glad to see that you got the answer by yourself. Good luck :)
  • @GioGarcia are you sure the validator is actually being triggered?
  • still not working, I'm trying to validate if it is not a string.
  • so just change === to !==. I made an update
  • still not working it still don't show the error message if I input number
  • still not working.. you can redo my code.. I think my point is if the input is number then it will show the message. does $.isNum() or isNaN() could work?
  • @RobertHovhannisyan it's coming from a specific source, the one being validated input type="text" where the value is always a string even if all characters are numerals ("123" === ""+"123") evaluates to true