-1

I would like to find out how you can tell if a character in a variable is a letter or number

for example: if I used the code: ABC123

How would I find out if a variable followed that pattern so if a inputted code would be DNM567 it would print "correct" But if a code was DNM56T it would print "incorrect".

Many thanks

Max Kyte
  • 1
  • 1

2 Answers2

0

You can use regular expressions, or linearly scan the character array to ensure that no letter comes after a number.

More information about the question would be helpful.

Citronen
  • 4,050
  • 4
  • 16
  • 20
0

you can use regular expression:

if(Regex.IsMatch(myString, "^[A-Za-z]{3}[0-9]{3}$")) 
{
    // you got the right pattern...
}

edit: this is C# but regular expression can be found in almost any OOP language out there.

Sagiv b.g
  • 30,379
  • 9
  • 68
  • 99