Solved

Regular exp

Posted on 2006-11-10
12
189 Views
Last Modified: 2010-03-31
Hi experts,
  I need regular ex. which allow only
a-zA-Z0-9. in any position.
means this is allowed

man756, 7manish, man9wad
but no allowed
manish, 78
thanks.



0
Comment
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
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 86

Expert Comment

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

Author Comment

by:Manish
ID: 17913612
but i think this will allow only alpha?
0
 
LVL 11

Author Comment

by:Manish
ID: 17913623
or numeric
but i want combination of both.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17913884
try using this:

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

Author Comment

by:Manish
ID: 17914058
no it is not working
0
 
LVL 23

Expert Comment

by:Ajay-Singh
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

by:CEHJ
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

by:Manish
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

by:Manish
ID: 17930223
import org.apache.regexp.RE;
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 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

by:Manish
ID: 17930295
Thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17930420
:-)
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question