Remove slash / delimiters and add the Dart delimiters : r'^[a-z ,.'-]+$ '
Remove slash / delimiters and add the Dart delimiters : r'^[a-z ,.'-]+$ '
use below method for validate full name
String fullNameValidate(String fullName) {
String patttern = r'^[a-z A-Z,.\-]+$';
RegExp regExp = new RegExp(patttern);
if (fullName.length == 0) {
return 'Please enter full name';
} else if (!regExp.hasMatch(fullName)) {
return 'Please enter valid full name';
}
return null;
}
Create a static final field for the RegExp to avoid creating a new instance every time a value is checked. Creating a RegExp is expensive.
static final RegExp nameRegExp = RegExp('[a-zA-Z]');
// or RegExp(r'\p{L}'); // see https://stackoverflow.com/questions/3617797/regex-to-match-only-letters
static final RegExp numberRegExp = RegExp(r'\d');
Then use it like
validator: (value) => value.isEmpty
? 'Enter Your Name'
: (nameRegExp.hasMatch(value)
? null
: 'Enter a Valid Name');
It seems to me you want
RegExp(r'[!@#<>?":_`~;[\]\\|=+)(*&^%0-9-]').hasMatch(value)
Note that you need to use a raw string literal, put - at the end and escape ] and \ chars inside the resulting character class, then check if there is a match with .hasMatch(value). Notre also that [0123456789] is equal to [0-9].
As for the second pattern, you can remove the digit range from the regex (as you need to allow it) and add a \s pattern (\s matches any whitespace char) to disallow whitespace in the input:
RegExp(r'[!@#<>?":_`~;[\]\\|=+)(*&^%\s-]').hasMatch(value)