Validation on Routes

I have a route that is something like this

  match '/:token' => 'users#new'

This token is 8 digit alphanumeric. I want to add validations on it so that it matches with the route only when there are 8 digits present in token.

How can I do that.

Hi!

Try this:

match ‘:/:token’ => ‘users#new’ , constraints => { :token => /[a-zA-Z0-9]{8}/ }

There is \w in regexp that means letter, number and underscore (accordlying rubular.com) , but I don’t know if your token accepts underscores.

No there are no underscores. only alphabets and numbers.

Hi!

Try this:

match ‘:/:token’ => ‘users#new’ , constraints => { :token =>

/[a-zA-Z0-9]{8}/ }

There is \w in regexp that means letter, number and underscore (accordlying

rubular.com) , but I don’t know if your token accepts underscores.

No there are no underscores. only alphabets and numbers.

So, try using /[a-zA-Z0-9]/ as your constraint. I can’t remember a shortcut for alphanumeric, if there is one.