Campbell Ritchie wrote:But 111111AAA1 has more than 8 digits in, and parsed as a hexadecimal will throw a NumberFormatException.
Campbell Ritchie wrote:You need to write down what those two regular expressions would match, then you will see what they are useful for.
You have been confusing us in this thread: you started saying ". . . whether a String contains Alphabet," and later said you want to check whether the String was a number. Then you said "not alphabet"
Rob is correct; you want to check that the input consists entirely of digits.
111111AAA1 is a valid number in hexadecimal; the comment about 8 digits shows that the parsing method will not help tell whether it is a number.
Pawan Choure wrote:i want to do it by using
Hope you got what i want....
Rob Spoor wrote:I said before that ^ and $ mean the start and end of the String. You literally are asking for the start, exactly one letter, then the end. You actually want to search for one letter regardless of where in the String it is. Well, letters, punctuation characters, whitespace, and anything else that isn't a digit. Even if you get your regex to work for letters, I can simply add something like !, ~, ? or even spaces and your regex will accept it all. That's why I suggested to allow valid input instead of blocking invalid input. The valid characters (\d) are much more limited than the invalid ones (everything else).
Paul Clapham wrote:I have to say that "Must not contain any letters" is a very strange requirement, quite apart from the apparent difficulty of writing a regex to implement it. That certainly isn't the same as "Must only contain digits", which would be a reasonable requirement and is something you almost said earlier in the thread.
So before we flounder about any more could you clarify what is your exact requirement?
Matthew Brown wrote:What Paul's getting at is that that's a bit unusual. Would these be valid?
They don't have letters in. Are you really sure they should be valid? If not, then forget about the letters and define your requirements in terms of what is allowed, not what is forbidden.
You have already been told what you can use.
Pawan Choure wrote: . . . i need regex for the following mentioned scenario. . . .