1

I'm trying to validate the variable name where it should not start with number but can include numbers

[RegularExpression(@"^[A-Z0-9_]+$", ErrorMessage = "Only Alphanumeric characters and Underscore ('_') is allowed. All letters must be in Upper Case.")]

The above expression doesn't restrict the starting string with Number.

1
  • Use: ^[^0-9]\w*$ Commented Jul 12, 2021 at 3:33

3 Answers 3

1

Try this regular expression for validating a string which is not starting with a number.

[A-Z_][A-Z0-9_]*
Sign up to request clarification or add additional context in comments.

Comments

1

Try using this regular expression for validating a string that doesn't start with a number, but can contain a number

^[^0-9]\w*$

and you can always use this website for testing can modifying your RegEx

https://regexr.com/

Comments

1

This is the right answer, It will prompt error if string starts with a number.

^(?!^[0-9].*$).*

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.