I want to exclude spaces when validating a textbox in vb.net.
Here is the current ValidationExpressopn value:
ValidationExpression=”^([a-zA-Z0-9_-.\’]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$” />
When user inputs space in textbox, I dont want that to render as error.
Example: I include spaces after “1@test.com “
This should not be treater as incorrect data in the textbox.
Any ideas?
If your spaces are leading or trailing you can do a Trim on the expressionToValidate before comparing to your regexp
If you want to modify the regExp to take into account the trailing spaces:
If you want to exclude also leading spaces add an extra ( *) at the beginning of the expression:
Btw – the regExp you are providing is broken – I used the one found here (expression to validate email addresses)