AlphaGit / ng-pattern-restrict

Allowing only certain inputs based on a regex pattern, for AngularJS
http://alphagit.github.io/ng-pattern-restrict/
MIT License
47 stars 32 forks source link

Help with Regexes #36

Closed senthilsendhil closed 8 years ago

senthilsendhil commented 8 years ago

in above regs.. i cant empty the string.. where to add /d??

AlphaGit commented 8 years ago

Your regex does not allow for empty string. Try this one:

^([0-9,*._]{0,10})$

AlphaGit commented 8 years ago

@senthilsendhil Hi! I just noticed the regex I gave you had a slight error. I already corrected it.

However, were you able to solve the problem that you were facing? Do you need any help?

senthilsendhil commented 8 years ago

@AlphaGit Its was working, one more doubt , I like to make some dynamic regs like i want to set length dynamic ^([0-9,*._]{0,})$

AlphaGit commented 8 years ago

Sure! In that case you probably will want to use the * quantifier, which will match zero or more elements of the expression to the left of it. I recommend checking this site out, that helps in understanding and testing regular expressions: https://regex101.com/

AlphaGit commented 8 years ago

Hi @senthilsendhil! Were you able to solve the problem you were having?

senthilsendhil commented 8 years ago

Hi ,

Sorry for late reply , yes I solved , I got new problem, hope you can help?

I want to restrict user entry for date format

AlphaGit commented 8 years ago

Hi, here's an example even using the library: https://plnkr.co/edit/QHgV7m9jlSLPImxcFif2?p=preview

senthilsendhil commented 8 years ago

Thanks lot , its worked , also I am trying to modify dd/mm/yyyy with if its date user can enter only 01 - 31 and for month 01 - 12 ...

AlphaGit commented 8 years ago

The regex expression for such restriction will be really complicated, since I understand that the next step will be to use the right amount of days in the right months, and consider leap years.

You're really best suited (and will have less problems) using a date input or a date widget.

Just so you have a glance, this is the validation for days 1-31, without considering the right months:

(0?[1-9]|[12][0-9]|3[01])?

AlphaGit commented 8 years ago

@senthilsendhil I'll be closing this ticket. If you have any questions regarding the library or project, feel free to open a new ticket. If you have more questions about regexes, I really suggest looking into some documentation in them for JavaScript (MDN is a great resource) or ask in StackOverflow. I also have no problem with helping out but it's a little bit outside of the scope of the project, but you can contact me through some other medium.

Thanks!