Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

Help with forcing user top enter "+" or "-" as first character in a textbox

Hello,

How do I prompt the user with a message if he/she does not enter enter "+" or "-" as first character in a text box? I am using VB.NET with my ASP.NET application.

Thanks,

Victor
Avatar of rpkhare
rpkhare
Flag of India image

You need to make use of substring method to check first character.

To display a message, refer to my answer in your other post.
Avatar of Victor  Charles

ASKER

Since the value of my textbox is for example +999, do you mean

Dim literal As String = textbox.text
Dim substring As String = literal.Substring(0, 1)
if substring <> "+" or substring <> "-"  then
message
endif

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
For empty string, substring is going to generate error as @jamie wrote above. You can use any of the approach.

Your attempted code looks correct.