Results 1 to 3 of 3
- 10-03-2011, 11:47 AM #1
Member
- Join Date
- Sep 2011
- Posts
- 3
- Rep Power
- 0
Regular expression for alphanumeric characters containing space ,"_" and "-"
1. First word should contain only [0-9a-zA-Z]
2. Second word can contain any of these characters[0-9a-zA-Z],space,"_" and "-".But same characters(space,"_" and "-") cannot be consicutive.For examples "__","--"," ","_-" are invalid.But "- _" is valid.
3.
i) Hello world_-(invalid)
ii) Hello world_ -(valid)
iii) Hello world--(invalid)
iv) Hello world- -(valid)
v) Hello world_ _(valid)
vi) Hello world(invalid) - 2 spaces
- 10-03-2011, 01:42 PM #2
Re: Regular expression for alphanumeric characters containing space ,"_" and "-"
Can you show your regexp?
Skype: petrarsentev
http://TrackStudio.com
- 10-03-2011, 06:22 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 3
- Rep Power
- 0
Re: Regular expression for alphanumeric characters containing space ,"_" and "-"
Java Code:public static boolean isAlphaNumericWithSpace(String input) { return isAlphaNumericWithSpace(input, "_\\-"); } public static boolean isAlphaNumericWithSpace(String input, String additionalValidChars) { /* patternString contains a space */ String patternString = "([a-zA-Z0-9]+([ ][a-zA-Z0-9])*)+"; if (additionalValidChars != null && additionalValidChars.length() > 0) { patternString = "([a-zA-Z0-9]+[ ]?(([" + additionalValidChars + "][a-zA-Z0-9 ])*)?[" + additionalValidChars + "]?)+"; } Pattern pattern = Pattern.compile(patternString); return pattern.matcher(input).matches(); }
Similar Threads
-
SAXParseException: The prefix "x" for element "x:xmpmeta" is not bound
By Quinn-CD in forum Web FrameworksReplies: 0Last Post: 06-24-2011, 08:14 PM -
connection = DriverManager.getConnection(DATABASE_URL,'"+userid +"','"+password+"');
By renu in forum New To JavaReplies: 3Last Post: 10-12-2010, 04:21 PM -
How to change my form design from "metal" to "nimbus" in Netbeans 6.7.1?
By mlibot in forum New To JavaReplies: 1Last Post: 01-21-2010, 09:20 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks