-
Notifications
You must be signed in to change notification settings - Fork 58
Regular Expressions (Regex)
From the example displayed, I introduce the custom regular expression, there is no limitation on regex itself and you can even use the pipe " | " within it and without being scared of interfering with the other validation filters BUT you have to follow a specific pattern (a writing pattern that is), and if you don't, well it will simply fail. Let's explain how it works...
Regex validation is divided in 4 specific parts (Step #1-4).
Let's use the previous Examples #6 and extract the information out of it to see how it works. Step #1-4 are for explanation only, at the end we show the full regex (make sure there is no spaces).
-
Start & end the filter with the following
regex: :regex
which tells the directive where to extract it. -
Custom error message
YYWW
(what do we want to display to the user, it will be appended to INVALID_PATTERN, refer to the translation file. In english it will display the following: Must be following this format: YYWW) -
Followed by a separator which basically says... after
:=
separator comes the regex pattern -
Custom regex pattern
^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$
Final code (without spaces):
regex:YYWW:=^(0[9]|1[0-9]|2[0-9]|3[0-9])(5[0-2]|[0-4][0-9])$:regex
Contents
- Angular-Validation Wiki
- Installation
- Demo
- Code Samples
- Functionalities
- Custom Validations
- Properties & Options
- Validators
- Tests
- Misc