Star79
asked on
Need a regular expression in c#
Hello,
I need a regular expression in c# which accepts + only in the begining. Currently i am using this
[-+]?[0-9]* but this will allow special character + to be inserted anywhere in the string.
Regards,
Rithesh
I need a regular expression in c# which accepts + only in the begining. Currently i am using this
[-+]?[0-9]* but this will allow special character + to be inserted anywhere in the string.
Regards,
Rithesh
I think what you really need is
^[-+]?[0-9]+
Actually, you might need to add a bit more to the pattern. The above would still allow the following:
+123+
+123ABC
etc. Let's add the end-of-line-marker as well:
Change the * to a + if you require at least one digit, as pmasotta demonstrates.
+123+
+123ABC
etc. Let's add the end-of-line-marker as well:
^[-+]?[0-9]*$
Change the * to a + if you require at least one digit, as pmasotta demonstrates.
the former one also match single + or - signs
+
-
this one requires a valid integer number per line
+
-
this one requires a valid integer number per line
^[-+]?[0-9]*$
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window