Regular expression which allow only characters or space
you can use this
/^([a-zA-Z]+\s)*[a-zA-Z]+$/
regex to allow only alphabets and no special characters, with no space at the beginning
First of all, you missed the beginning of string anchor ^
.
Secondly, the inverse character class [^-\s]
is a good attempt at not allowing spaces, but at the same time it does allow other special characters to be at the beginning of the string, which we do not want. Instead, we could just something very similar to the second character class, just without the \s
: [a-zA-Z]
.
Full regex:
^[a-zA-Z][a-zA-Z\s]*$
javascript regex allow only letters . - and spaces. And all should be from 2 to 256 symbols
You can use this regex:
var regex = /^[a-z][a-z.\s-]{1,255}$/i;
Related Topics
How to Pass Data from Flask to JavaScript in a Template
Javascript Backslash (\) in Variables Is Causing an Error
How to Remove a Json Inside a Json by a Key Using Jquery
How to Compress an Image Via JavaScript in the Browser
Refresh Leaflet Map: Map Container Is Already Initialized
Executing Nodejs Script File in PHP Using Exec()
Assigning Id to All Elements of a Page in Angular Automatically
How to Stop All Ajax Process in the Page Using Jquery
Export Array of Objects into Excel Using JavaScript
How to Modify Chartjs Tooltip So I Can Add Customized Strings in Tooltips
Javascript to Download a File from Amazon S3 Bucket
Best Way to Show a Loading Spinner/Gif While My React Component Is Fetching Via Ajax
Node.Js MySQL Query in a for Loop
How to Close Sweet Alert on Ajax Request Completion
Javascript: How to Read a Hand Held Barcode Scanner Best