Predefined validators

Leda has a number of predefined validators both international and local.

Feel free to contact contributors to add another one you think can be useful for you or other people.

Another way to add a predefined validator is to make the job and send us a pull request.

TypeDescription
type PredefinedValidator =
| 'creditCardNumber'
creditCardNumber uses a few algorithms
including Luhn algorithm
to check if it is a valid credit card number.
| 'email'

email checks if there is a @ and a . in the right oder and quantity.

Also checks that no forbidden symbols are present

| 'url'

url checks different types of urls, e.g.

foo.com
www.foo.com
http://foo.com/home
https://foo.com/home
https://localhost:9000/
http://142.42.1.1/
https://www.foo.com/foo/?bar=baz&abc=42&etc
etc. will pass.

http://
http://??/
http:// shouldfail.com
http://3628126748
http://1.1.1.1.1
and other invalid urls will not pass validation

Validation of non-latin characters is also supported.
E.g. you can validate Chinese, Arabic, Indian, cyrillic etc urls


<>
  <L.Div _flex  _mb-3>
    <L.Input
      form='commonValidators'
      name='creditCard'
      validator='creditCardNumber'
      invalidMessage={<i>Please enter a valid card number</i>}
      isRequired
      placeholder='card number'
      _w-48
      _mr-3
    />
    <L.Input
      form='commonValidators'
      name='email'
      validator='email'
      invalidMessage={<i>Please enter a valid email</i>}
      isRequired
      placeholder='email'
      _w-48
      _mr-3
    />
    <L.Input
      form='commonValidators'
      name='url'
      validator='url'
      invalidMessage={<i>Please enter a valid url</i>}
      placeholder='url'
      _w-48
      _mr-3
    />
  </L.Div>
  <L.Button
    form='commonValidators'
    onValidationFail={({ invalidForms }) => log(invalidForms)}
    shouldScrollToInvalidFields
    scrollOffset={100}
    onClick={({ form }) => log(form)}
  >
    Submit
  </L.Button>
</>