Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Regular exp

Posted on 2006-11-10
Medium Priority
193 Views
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
Question by:Manish
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6
• 4
• 2

LVL 86

Expert Comment

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

LVL 11

Author Comment

ID: 17913612
but i think this will allow only alpha?
0

LVL 11

Author Comment

ID: 17913623
or numeric
but i want combination of both.
0

LVL 23

Expert Comment

ID: 17913884
try using this:

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

LVL 11

Author Comment

ID: 17914058
no it is not working
0

LVL 23

Expert Comment

ID: 17914171
its working for me!

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

LVL 86

Expert Comment

ID: 17914184
Try

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

LVL 11

Author Comment

ID: 17930220
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

LVL 11

Author Comment

ID: 17930223
import org.apache.regexp.RE;
0

LVL 86

Accepted Solution

CEHJ earned 200 total points
ID: 17930246
Sorry -  typo

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

LVL 11

Author Comment

ID: 17930295
Thanks.
0

LVL 86

Expert Comment

ID: 17930420
:-)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the bâ€¦
The viewer will learn how to implement Singleton Design Pattern in Java.