0

I have a textbox and have to use the regular expressions in asp.net

My text should not allow the spaces in first and last place.

Output should be:

Valid: [India Bangalore]

Not valid: [ India Bangalore ]

i.e : user can enter the spaces in between the words but not in first position and last position.

If you have solution in JavaScript that is also fine.

1
  • Why not call .Trim() and don't bother the user about the spaces? Commented Oct 19, 2011 at 15:53

2 Answers 2

1

Trim() should remove any trailing or leading spaces.

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

Comments

0

Try this please :

^[^\s].*[^\s]$

It simply match input which: not to start with any white space ^[^\s] followed by any character even white spaces .* and not end with any white space [^\s]$.

Any way calling Trim() method on input string in server-side is much easy .

Comments

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.