dart regex validation code example
Example 1: dart regex,regex dart
// Here's a regular expression for one or more digits.
var numbers = RegExp(r'\d+');
var allCharacters = 'llamas live fifteen to twenty years';
var someDigits = 'llamas live 15 to 20 years';
// contains() can use a regular expression.
assert(!allCharacters.contains(numbers));
assert(someDigits.contains(numbers));
// Replace every match with another string.
var exedOut = someDigits.replaceAll(numbers, 'XX');
assert(exedOut == 'llamas live XX to XX years');
Example 2: flutter regex validation
You could make the first part optional matching either a + or 0 followed by a 9. Then match 10 digits:
^(?:[+0]9)?[0-9]{10}$
^ Start of string
(?:[+0]9)? Optionally match a + or 0 followed by 9
[0-9]{10} Match 10 digits
$ End of string
Regex demo