trevorr/tsfv

Alternating true/false validation on a value

Closed this issue · 2 comments

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); })

@rafaelytakei Was the issue not in tsfv?

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