Skip to content

Commit

Permalink
Feature : new methods for string
Browse files Browse the repository at this point in the history
- digits, letters, alphanumeric
  • Loading branch information
nvshah committed Jun 20, 2022
1 parent 6465f00 commit d704ec1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/src/string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,35 @@ String buildString(void Function(StringBuffer sb) builderAction) {
builderAction(buffer);
return buffer.toString();
}

extension StringIsLetterOrDigits on String {
/// Returns `true` if all the characters in string are digits & there is atleast 1 character,
/// `false` elseways
bool get isDigit {
if (isBlank) {
return false;
}
final regex = RegExp(r'^\d+$');
return regex.hasMatch(this);
}

/// Returns `true` if all the characters in string are letters & there is atleast 1 character,
/// `false` elseways
bool get isAlpha {
if (isBlank) {
return false;
}
final regex = RegExp(r'^[a-zA-Z]+$');
return regex.hasMatch(this);
}

/// Returns `true` if all the characters in string are either digits or letters
/// & there is atleast 1 character, `false` elseways
bool get isAlNum {
if (isBlank) {
return false;
}
final regex = RegExp(r'^[a-zA-Z0-9]+$');
return regex.hasMatch(this);
}
}

0 comments on commit d704ec1

Please sign in to comment.