Hi,
I need a validation using regex just the pattern i have. The user has to enter digits and after the digits one letter. User can have up to six digits or less
eg:

1234(G)
123456(K)
12(O)

## All 9 Replies

are the () required? Can they enter zero digits? Does the letter have to be upper case?

yes the () are required and letters has to be uppercase.. i guess he can't enter 0's

I don't mean the number zero, I mean a count of zero. You said "six digits or less". Zero is less than six. So is "(A)" valid or does it have to have at least one digit?

I don't mean the number zero, I mean a count of zero. You said "six digits or less". Zero is less than six. So is "(A)" valid or does it have to have at least one digit?

it has to have at least 3 digits

``Regex reg = new Regex(@"^\d{3,6}\([a-zA-Z]\)\$");``

Momerath, I can see you are pretty familiar with Regex. But Iam not. I would like to learn then more.
So I will ask right here. How to do (seperate) the regex, that will check for more conditions?
Is the seperator the backslash '\'? Or how would be the easiest way to combine it?

``Regex reg = new Regex(@"^\d{3,6}\([a-zA-Z]\)\$");``

It worked thx :)

Momerath, I can see you are pretty familiar with Regex. But Iam not. I would like to learn then more.
So I will ask right here. How to do (seperate) the regex, that will check for more conditions?
Is the seperator the backslash '\'? Or how would be the easiest way to combine it?

It really depends on what kind of conditions you want to check.

And no, the \ is an escape character, if you have conditions that you want to check and it needs to match one of, you use the | character, for example "[a|s|z]" would mean it needs to be one of 'a' or 's' or 'z'.

now i want a regex pattern that accepts from 3 to 6 digits.. and only A,M or G at the end
eg:
1234G

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.