javascript - Ui-router route parameter with regex - Stack Overflow

I feel like this is simple but I can't get it to work...I am using Ui-Router 2.11 which includes o

I feel like this is simple but I can't get it to work...

I am using Ui-Router 2.11 which includes optional parameters with regex expressions.

I have this url which works

'/event/{eventId:[0-9]}'

it filters out everything that isn't numeric, however it only works for 1 character of input (so only 0 through 9).

I want to replace it with an expression that checks to make sure all characters in the input are numeric so I can have any input as long as it's all numbers.

I tried using expressions from this thread

'/event/{eventId:^[0-9]+$}'

but it doesn't work. The other examples include forward slashes which I can't use(via the warning in the ui-router docs). This feels like it should be incredibly simple, what am I doing wrong?

I feel like this is simple but I can't get it to work...

I am using Ui-Router 2.11 which includes optional parameters with regex expressions.

I have this url which works

'/event/{eventId:[0-9]}'

it filters out everything that isn't numeric, however it only works for 1 character of input (so only 0 through 9).

I want to replace it with an expression that checks to make sure all characters in the input are numeric so I can have any input as long as it's all numbers.

I tried using expressions from this thread

'/event/{eventId:^[0-9]+$}'

but it doesn't work. The other examples include forward slashes which I can't use(via the warning in the ui-router docs). This feels like it should be incredibly simple, what am I doing wrong?

Share Improve this question edited May 23, 2017 at 12:24 CommunityBot 11 silver badge asked Sep 5, 2014 at 13:53 Matt Foxx DuncanMatt Foxx Duncan 2,0943 gold badges23 silver badges40 bronze badges 1
  • 1 try removing the $ sign. – vks Commented Sep 5, 2014 at 13:56
Add a ment  | 

1 Answer 1

Reset to default 6

Judging by the linked documentation, I think either one of these expressions will do the trick:

'/event/{eventId:[0-9]+}'//match 1 or more digit
'/event/{eventId:[0-9]{1,}}'//same as above, alternative notation

If possible, I would replace [0-9] with \d, though. It just looks cleaner.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401994a4626144.html

相关推荐

  • javascript - Ui-router route parameter with regex - Stack Overflow

    I feel like this is simple but I can't get it to work...I am using Ui-Router 2.11 which includes o

    3小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信