trevorr / tsfv

Typescript Fluent Validation Library
ISC License
5 stars 0 forks source link

Alternating true/false validation on a value #2

Closed rafaelytakei closed 4 years ago

rafaelytakei commented 4 years ago

Hi, first of all thanks for creating this alternative to v8n with TS support, it's helping me a lot! I'm currently having trouble with a simple validation. Basically I have an input field #name, which i'm trying to validate comparing to the nameRegex value, which should return true if it has more than 3 characters basically, everytime I press the #validate button.

However, whenever I try to validate a valid name, it alternates between true/false if I validate it more than once, when it was supposed to always return true. Do you know what could be the problem?

Here is part of my code:

const nameRegex = /^([A-zÀ-ú '´]{3,})$/g;

$('#validate').on('click', function() { let name= $('#name').val(); console.log(name); let nameValidation = tsfv.string().pattern(nameRegex).test(nome); console.log(nameValidation); })

trevorr commented 4 years ago

@rafaelytakei Was the issue not in tsfv?

rafaelytakei commented 4 years ago

Oh I ended up managing to fix it by changing the regex, I think it's some bug with the /g by the end