Solved

Regular exp

Posted on 2006-11-10
12
184 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
  • 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
bunnyEars challenge 6 65
mockito example issue 8 35
micro services spring boot application error 3 34
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

762 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now