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

Regular exp

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
Manish
Asked:
Manish
  • 6
  • 4
  • 2
1 Solution
 
CEHJCommented:
x.matches("[a-zA-Z0-9]+");
0
 
ManishLeadAuthor Commented:
but i think this will allow only alpha?
0
 
ManishLeadAuthor Commented:
or numeric
but i want combination of both.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Ajay-SinghCommented:
try using this:

if(!x.matches("([a-zA-Z]+)|([0-9]+)")) {
    // Matches
}
0
 
ManishLeadAuthor Commented:
no it is not working
0
 
Ajay-SinghCommented:
its working for me!

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

final String RE = "[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+";
0
 
ManishLeadAuthor Commented:
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
 
ManishLeadAuthor Commented:
import org.apache.regexp.RE;
0
 
CEHJCommented:
Sorry -  typo

"^[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+[A-Za-z]+|[A-Za-z]+[0-9]+$";
0
 
ManishLeadAuthor Commented:
Thanks.
0
 
CEHJCommented:
:-)
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now