• Status: Solved
• Priority: Medium
• Security: Public
• Views: 199

Regular exp

Hi experts,
I need regular ex. which allow only
a-zA-Z0-9. in any position.
means this is allowed

but no allowed
manish, 78
thanks.

0
Manish
• 6
• 4
• 2
1 Solution

Commented:
x.matches("[a-zA-Z0-9]+");
0

but i think this will allow only alpha?
0

or numeric
but i want combination of both.
0

Commented:
try using this:

if(!x.matches("([a-zA-Z]+)|([0-9]+)")) {
// Matches
}
0

no it is not working
0

Commented:
its working for me!

boolean "!x.matches("([a-zA-Z]+)|([0-9]+)")" is true for man756, 7manish, man9wad
and false for manish, 78
0

Commented:
Try

final String RE = "[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+";
0

public class abcd {

public static void main(String[] args){
RE re =new RE("^[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]\$");
System.err.println(re.match("manish123"));//true
System.err.println(re.match("222man"));//true
System.err.println(re.match("manish"));//false
System.err.println(re.match("222"));//false
System.err.println(re.match("man5man"));//true
System.err.println(re.match("';''"));//false

}

}

manish123 is coming as false. I need it true.
0

import org.apache.regexp.RE;
0

Commented:
Sorry -  typo

"^[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+\$";
0

Thanks.
0

Commented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.