user455915
user455915

Reputation: 3

Text box validation using regular expression in asp.net

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.

Upvotes: 0

Views: 619

Answers (2)

Dindar
Dindar

Reputation: 3235

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 .

Upvotes: 0

Sabre
Sabre

Reputation: 2400

Trim() should remove any trailing or leading spaces.

Upvotes: 1

Related Questions