Questions tagged [regula]

Regula is an annotation-based form-validation library for client-side validation written in JavaScript

Regula is an annotation-based form-validation library for client-side validation written in JavaScript. Validation constraints are attached to input elements in a manner similar to HTML5 constraints, via the data-constraints attribute:

<input type="text" 
       id="social" 
       name="social" 
       data-constraints="@Required @Pattern(regex=/\d{3}-\d{2}-\d{4}/)" />

Regula also provides the ability to attach custom constraints to elements:

regula.custom({
   name: "MustBe42",
   defaultMessage: "The answer must be equal to 42",
   validator: function() {
      return this.value == 42;
   }
});

And then:

<input type="text" name="something" data-constraints='@MustBe42' />

Parameters are also supported:

regula.custom({
   name: "MustBeSpecifiedNumber",
   params: ["number"],
   defaultMessage: "The answer must be equal to {number}",
   validator: function(params) {
      return this.value === params.number;
   }
});

And then:

<input type="text" name="something" data-constraints='@MustBeSpecifiedNumber(number=10)' />

Regula also provides the ability to segment validation through validation groups:

<input type="text" name="street" data-constraints='@Required(groups=[AddressGroup])' />
<input type="text" name="city" data-constraints='@Required(groups=[AddressGroup])' />
<input type="text" name="state" data-constraints='@Required(groups=[AddressGroup])' />
<input type="text" name="zip" data-constraints='@Required(groups=[AddressGroup])' />

Validation can then be performed like so:

var constraintViolations = regula.validate({
    groups: [regula.Group.AddressGroup] //AddressGroup property is automatically added
});

Regula also supports HTML5 constraints (either through native browser-support, or a third-party shim) and asynchronous validation.

More information about Regula is available here.

11 questions
3
votes
2 answers

Validate range of dates with Regula

Is there any way to use @Range to validate a range of dates in Regula? (ditto @Min and @Max) Or do I need to use @Custom? @Range(min= and @Range(max= do not seem to accept anything of the type Date - only numbers or strings.
sq33G
  • 3,174
  • 1
  • 22
  • 35
2
votes
1 answer

Check that a pattern does not match

In Regula, how can I have a constraint that does NOT match a pattern? I can use @Pattern like this: But let's say that /[0-9]-[A-Z]{3}-[0-9]{4}/ is a…
1
vote
2 answers

regex For Float Numbers with Limits

I need regex Expression for Floating and whole numbers that have the limit like it will accept 1 or 2 digit before point and 1 or 2 digits after point. Whole number limit should be 2 digit. What should be valid: - 1.1 - 11.1 - 1.11 - 11.11 …
Fizzah
  • 43
  • 2
  • 12
1
vote
1 answer

Does Regula.js now support remote/asynchronous custom validations?

According to the release doc, Regula 1.3.0 should support async validation. It seems that compound constraints are able to take an option of async in some way. Does this hold true for custom validations as well? What would be the syntax for this?
sq33G
  • 3,174
  • 1
  • 22
  • 35
0
votes
2 answers

Is it possible to create a validation with multiple regex pattern using regula?

I need to check given text is validate as a wep key. So I need to check all below regular expressions for one field. Is there a way to do that with…
Necip Onur Uzun
  • 1,085
  • 3
  • 12
  • 16
0
votes
1 answer

Regular Expressions, containing specific words

I need to specify that my user name has to start with one of two words, followed by a backslash. It can only accept the words cat or dog at the beggining and then a backslash is expected, for example: cat\something dog\something Both are…
Sam
  • 37
  • 5
0
votes
1 answer

How to prevent the regex from taking whitespaces

I was making a regular expression which can have the phone number of any length and can have the ( + and ) anywhere in the number. ^[\s()+-]*([0-9][\s()+-]*){6,20}$ But this regular expression is taking the spaces in it which is not correct. can…
vaibhav
  • 666
  • 1
  • 9
  • 29
0
votes
1 answer

Regula Form Validation Crashes on validation

Im using this library for the first time, maybe Im making some stupid mistake but Im stuck. I am using Play Framework 2.0 to serve regula 1.3.3 like this