DarkW1nter
DarkW1nter

Reputation: 2861

limit textbox to x number of characters

I have a textbox on an aspx page which I have limited to accept 250 characters. This works fine when a user just types data in, but if they paste the textbox will accept way more. Is there a way I can get around this? I dont want to disable pasting in the textbox though.

thanks again

Upvotes: 0

Views: 727

Answers (3)

Anton Vidishchev
Anton Vidishchev

Reputation: 1399

You can add a validator to the page which will check the string length. Then you will get the validation error instead of posting a long string.

You can use RegularExpressionValidator and validation expression like ".{0,250}" for that.

Upvotes: 1

Marco Johannesen
Marco Johannesen

Reputation: 13134

maxlength="250" 

And you shouldnt be able to paste more than 250 chars. That being said, its the browser that does the "counting/limiting" so it can be bypassed. But then you could limit in the form submit or something

Otherwise you could do it with jquery. But maxlength should be enough?

Upvotes: 0

Bajji
Bajji

Reputation: 2393

Did you use MaxLength property of the textbox?

Upvotes: 0

Related Questions