6.4.1 Regex demo - quan1997ap/angular-app-note GitHub Wiki
CY: Nếu dùng pattem trong angular template-driven form . sẽ đặt regex trong //
pattem = /^(\d+w\s?)?(\d+d\s?)?(\d{1,2}h\s?)?(\d{1,2}m\s)?(\d{1,2}s)?$/
VD1:
/^[a]+$/ : Chuỗi hợp lệ sẽ là
+ bắt đầu bằng kí tự a ( các kí tự sau dấu [] )
+ Có thể lặp lại kí tự a 1 hoặc nhiều lần
VD2:
^[0-9]+$ : Chuỗi hợp lệ sẽ là
+ bắt đầu bằng kí tự số từ 0->9 ( các kí tự sau dấu [] )
+ Có thể lặp lại kí tự 0->9 1 hoặc nhiều lần
VD3:
^[0-9]{1,10}[mdyhms]|[ms]$
+ bắt đầu là số. tối đa nhập 10 chữ số
+ kết thúc bằng m,d,y,h, ms
Vd: 1m, 1h, 1ms
VD4: Regex 1h 1m 1ms
https://stackoverflow.com/questions/55165229/regex-to-test-space-separated-characters
^(\d+w\s?)?(\d+d\s?)?(\d{1,2}h\s?)?(\d{1,2}m\s)?(\d{1,2}s)?$
^(\d{1,2}h\s?)?(\d{1,2}m\s?)?(\d{1,2}s)?$
Vd: 1h 1m 1ms
VD5: Regex mail
const str = '[email protected]';
const globalRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
console.log(globalRegex.test(str));
VD6: Password regex https://stackoverflow.com/questions/19605150/regex-for-password-must-contain-at-least-eight-characters-at-least-one-number-a
Minimum eight characters, at least one letter and one number:
"^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$"
Minimum eight characters, at least one letter, one number and one special character:
"^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$"
Minimum eight characters, at least one uppercase letter, one lowercase letter and one number:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$"
Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$"
Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character:
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$"