What is a regular expression that accepts only characters ranging from a to z?
Just for people using bash shell, instead of "+" use "*"
"^[a-zA-Z]*$"
^[A-Za-z]+$ To understand how to use it in a function to validate text, see this example
The pattern itself would be [a-z]
for single character and ^[a-z]+$
for entire line. If you want to allow uppercase as well, make it [a-zA-Z]
or ^[a-zA-Z]+$
Try to use this plugin for masking input...you can also check out the demo and use this plugin if this is what you may want...
Masked Input Plugin
As you can see in the demonstration that you can use both alphatbets and numbers in a combination for complex textbox validations where an user might want to type not only alphatbets(azAZ) but also with numbers too(ie. alphanumberics)...specific validations like accepting only numbers in particular format(eg.phone numbers) can be done...that is the case when you can use this plugin for different circumstances..
hope this helps...
Allowing only character and space in between words :
^[a-zA-Z_ ]*$
Regular Expression Library
None of the answers exclude special characters... Here is regex to ONLY allow letters, lowercase and uppercase.
/^[_A-zA-Z]*((-|\s)*[_A-zA-Z])*$/g
And as for different languages, you can use this function to convert letters to english letters before the check, just replace returnString.replace() with letters you need.
export function convertString(phrase: string) {
var maxLength = 100;
var returnString = phrase.toLowerCase();
//Convert Characters
returnString = returnString.replace("ą", "a");
returnString = returnString.replace("č", "c");
returnString = returnString.replace("ę", "e");
returnString = returnString.replace("ė", "e");
returnString = returnString.replace("į", "i");
returnString = returnString.replace("š", "s");
returnString = returnString.replace("ų", "u");
returnString = returnString.replace("ū", "u");
returnString = returnString.replace("ž", "z");
// if there are other invalid chars, convert them into blank spaces
returnString = returnString.replace(/[^a-z0-9\s-]/g, "");
// convert multiple spaces and hyphens into one space
returnString = returnString.replace(/[\s-]+/g, " ");
// trims current string
returnString = returnString.replace(/^\s+|\s+$/g, "");
// cuts string (if too long)
if (returnString.length > maxLength) returnString = returnString.substring(0, maxLength);
// add hyphens
returnString = returnString.replace(/\s/g, "-");
return returnString;
}
Usage:
const firstName = convertString(values.firstName);
if (!firstName.match(allowLettersOnly)) {
}