0

The url will be something like: meusite.com/user/{keyword here}

The user will only enter the key word, then I would a regex to validate word if this does not invalidate the URL, blank spaces, special characters and 5 to 22 characters.

2
  • 1
    What characters are valid characters for keyword? Commented Sep 23, 2011 at 19:56
  • any character that does not break the link Commented Sep 24, 2011 at 0:24

1 Answer 1

1

You just want to validate the keyword? Something like this should work:

/^[a-zA-Z0-9_\-\.\+]{5,22}$/

But why not just escape it?

Sign up to request clarification or add additional context in comments.

5 Comments

I do not understand, as well as escape?
@RidermandeSousaBarbosa: For example, changing spaces to %20 to make it valid. Why not do that?
in fact because of the complexity. Do you have any regex for transform the keyword in a valid url?
@RidermandeSousaBarbosa: No, why would you do that with regex? What language are you using? PHP offers urlencode, JavaScript offers encodeURIComponent()...
There is a method: Url.Encode() I think it will solve. Thank you. I had not thought of that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.