How to identify Alphabet or Number in a String

i want to check whether user typed correct string
like my string have specific pattern
WXYZ1234567
1st 4 latter will be alphabet and last 7 will be numbers only
so how i can check it
This is i tried
1 Method
split string in 4+7
then check it is a number or not
but in first 4 latter if number is there it will show it’s a text (text includes alphabets and numbers)
so this method fails

2nd Method
split string 4+7
check first 4 latter one by one if it is number or not
but this method is long

so please suggest me short method
Thanks

You’ll want to use Regular Expression aka. RegEx.

This Pattern should work for you:
[a-zA-Z]{4}[0-9]{7}
If you want only Capital Letters use:
[A-Z]{4}[0-9]{7}

This is a Great for testing Patterns:

Extension:
http://puravidaapps.com/tools.php

Block:
matches

2 Likes

Look in this thread and by using that extension you can accomplish what you want.

Sorry, my image shows the opposite but you understand at least how now

edit…Damn Ken you beat me by 30sec

/Boban

3 Likes

Thanks @Ken & @Boban for prompt reply

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.