Regex validation

(Kurt) #1

I need to use regex validation to ask which email, which cpf, which phone. But it is not being possible.

(Kurt) #2

this expression was allowed
^((11) [9][0-9]{4}-[0-9]{4})|((1[2-9]) [5-9][0-9]{3}-[0-9]{4})|(([2-9][1-9]) [5-9][0-9]{3}-[0-9]{4})$

but this other did not
^(?:(?:+|00)?(55)\s?)?(?:(?([1-9][0-9]))?\s?)?(?:((?:9\d|[2-9])\d{3})-?(\d{4}))$

I dont understand

(Daniel Beckett) #3

Hi Kurt,

Unfortunately any quantifiers aren’t supported as these can be dangerous in some expressions (search for an infinite value for example). The characters that cause problems are:

* (0 or more)
+ (1 or more)
? (0 or 1)
(Kurt) #4

I need this validation. What should I do?

Date: ^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[012])/[12][0-9]{3}$

Name: ^[A-ZÀ-Ÿ][A-zÀ-ÿ’]+\s([A-zÀ-ÿ’]\s?)*[A-ZÀ-Ÿ][A-zÀ-ÿ’]+$

Telphone: ^[1-9]{2}\ (?:[2-8]|9[1-9])[0-9]{3}-[0-9]{4}$

CPF (Individual Taxpayer Registry): ([0-9]{2}[.]?[0-9]{3}[.]?[0-9]{3}[/]?[0-9]{4}[-]?[0-9]{2})|([0-9]{3}[.]?[0-9]{3}[.]?[0-9]{3}[-]?[0-9]{2})

Hour: ([01][0-9]|2[0-3]).([0-5][0-9])

Kilogram: \d+(,\d{1,3})?

Email: (?:[a-z0-9!#$%&’+/=?^_{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])

(Daniel Beckett) #5

Hi Kurt,

Sorry but I can’t really troubleshoot the Regex for you but sites like regexr.com may be able to help with your testing.