So there have been plenty of questions, and filtering through a few, I still dont know how to go about this...
Pattern for:
- Alphabets ONLY, no case sensitivity, no limit on character count or words, minimum 3 characters...
I have
pattern="[A-z]{3,}"
That gives me everything, except that I'm limited to one word only... :-(
Edit: Let me be a little more clear on what I want the validation to achieve for me...
I'm using it to capture a person's name. But I do not want any special characters or numerals involved, so no "John Doe Jr.", as the '.' will get rejected, but I want to be able to capture double, or even single character portions, whilst maintaining 'global' 3 char minimum limit...
So there have been plenty of questions, and filtering through a few, I still dont know how to go about this...
Pattern for:
- Alphabets ONLY, no case sensitivity, no limit on character count or words, minimum 3 characters...
I have
pattern="[A-z]{3,}"
That gives me everything, except that I'm limited to one word only... :-(
Edit: Let me be a little more clear on what I want the validation to achieve for me...
I'm using it to capture a person's name. But I do not want any special characters or numerals involved, so no "John Doe Jr.", as the '.' will get rejected, but I want to be able to capture double, or even single character portions, whilst maintaining 'global' 3 char minimum limit...
Share Improve this question edited Jun 13, 2011 at 10:32 Abhishek asked Jun 13, 2011 at 10:08 AbhishekAbhishek 4,35012 gold badges43 silver badges52 bronze badges 5- Should "ab c" or even "a b c" be accepted? I mean, are you requesting at least a word 3 characters long or just 3 alphabetical character in total? – SJuan76 Commented Jun 13, 2011 at 11:02
- 1 As per my ment in my answer, I'd strongly remend not being too restrictive with name validation. There are a lot of very mon names which will fall foul of your rules as you have them at the moment. See also my answer here: stackoverflow./questions/3853346/… – Spudley Commented Jun 13, 2011 at 11:12
-
4
[A-z]
includes a lot of non alphabetic letters, for example square brackets, back-slashes, carets, underscores, and back-ticks. Try[A-Za-z]
instead. – Mike Samuel Commented Jun 13, 2011 at 12:03 - @SJuan76 - It wouldn't be favorable, but I wouldn't mind such additions... – Abhishek Commented Jun 14, 2011 at 1:26
-
@Abhishek you wouldn't mind
________Johny^420^YOLO___________
, butJohn Doe Jr.
is not acceptable? – Maksim Vi. Commented Oct 2, 2013 at 0:57
3 Answers
Reset to default 3All you have to do to allow spaces as well is to add a space to the character pattern where you have [A-z]
.
So it bees:
pattern="[A-z ]{3,}"
Hope that helps.
Note, however, that this will prevent other types of white space characters. I assume this is what you want, since you're being quite restrictive with the rest of the character set, but it's worth pointing out that non-breaking spaces, carriage returns, and other white space will be blocked in the above. If you want to allow them, use \s
instead of just a space: this will match any white space character.
Finally, it's worth pointing out that the standard alphabet is often insufficient even for plain English text. There are valid English words with accents, as well as apostrophes and other punctuation. You haven't specified what the field is being used for, so I'll assume this is not an issue, but I felt it was worth pointing out nevertheless.
It is difficult to see what is the question. You are matching a String, not a set of words. If your pattern is "a list of words, each of the words alphabetical only and separated by whitespace", then the regex would be
([A-Za-z]{3,}\\s*)+
Edited to answer to updated question.
[A-Za-z\\s]*([A-Za-z]{3,})+[A-Za-z\\s]* (works in Java)
How about pattern = "[A-z\s]{3,}"
?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745455413a4628462.html
评论列表(0条)