Java Regex to Validate Full Name allow only Spaces and Letters
What about:
- Peter Müller
- François Hollande
- Patrick O'Brian
- Silvana Koch-Mehrin
Validating names is a difficult issue, because valid names are not only consisting of the letters A-Z.
At least you should use the Unicode property for letters and add more special characters. A first approach could be e.g.:
String regx = "^[\\p{L} .'-]+$";
\\p{L}
is a Unicode Character Property that matches any kind of letter from any language
Regex which allows alphabets and spaces combination but not only spaces
Make your expression require one alphabet and then the additional alphabets and spaces are optional:
/^[A-Za-z]|[A-Za-z][A-Za-z\s]*[A-Za-z]$/
Also that \s
means any whitespace characters (tabs, newlines, carriage returns etc), not just space.
(edited: my earlier answer was flawed. This new one ensures input is either just one alphabet, or has to start and end with alphabet with spaces allowed only in between.
Related Topics
Getting Name of Parent Object from Value of Object
Hide Div If Value Is Blank (Javascript)
Javascript Scrollto Method Does Nothing
How to Check Whether Session Is Null or Not in JavaScript
Uncaught Typeerror: Cannot Read Property 'Click' of Null Chrome Extension
Creating a Multiple Choice Option in JavaScript
Bootstrap Slides Lagging While Using Multi Item Carousel Using Angular 6
How to Uncheck All Below Checkboxes When One Checkbox Is Unchecked
Removing Number from Notification Icon
Set Cookie on Page Load and Hide Div If Cookie Is Present
Can We Map Over Two Arrays At Same Time in Js
Method for Splitting String into Separate Cells in Sheets/App Script
How to Properly Import Function in a Reactjs File
Most Efficient Method to Groupby on an Array of Objects
How to Remove Errors Warnings from Console
Reactjs - How to Update Nested and "Normal" State Properties
Regular Expression Using JavaScript for Removing the Special Characters