v1.2.0
string_validator
Dart-Bibliothek zur Überprüfung und Bereinigung von Zeichenfolgen, insbesondere solchen aus Benutzereingaben.
466Likes 153.60030-Tage-Downloads160Pub-Punkte
AndroidiOSWebmacOSWindowsLinux
Zeichenfolgenvalidierung und -sanitisierung für Dart
Englischer Projektschnappschuss. Aktuelle Inhalte auf GitHub.
string_validator
=============
String validation and sanitization for Dart.
This is a new fork of validator.dart, which was originally a port of validator.js.
matches('foobar', 'foo').options is an object which defaults to { protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, allow_underscores: false }.options is an object which defaults to { require_tld: true, allow_underscores: false }.null if the input is not a date.NaN if the input is not a float.NaN if the input is not an integer.'0', 'false' and '' returns true. In strict mode only '1' and 'true' return true.<, >, &, ' and " with HTML entities.keep_new_lines is true, newline characters are preserved (\n and \r, hex 0xA and 0xD). Unicode-safe in JavaScript.options is an object which defaults to { lowercase: true }. With lowercase set to true, the local part of the email address is lowercased for all domains; the hostname is always lowercased and the local part of the email address is always lowercased for hosts that are known to be case-insensitive (currently only GMail). Normalization follows special rules for known providers: currently, GMail addresses have dots removed in the local part and are stripped of tags (e.g. some.one+tag@gmail.com becomes someone@gmail.com) and all @googlemail.com addresses are normalized to @gmail.com.To make using these validators and sanitizers more convenient, this package includes extension methods for each function. These methods can be called directly on a string instance, making the code more concise and readable.
Here are some examples of how to use the extension methods:
import 'package:string_validator/string_validator.dart';
void main() {
// Using Validator Extensions
String email = 'example@gmail.com';
bool isEmailValid = email.isEmail;
String url = 'https://example.com';
bool isUrlValid = url.isURL();
String ip = '192.168.0.1';
bool isIpValid = ip.isIP();
String alpha = 'abc';
bool isAlphaValid = alpha.isAlpha;
String numeric = '123';
bool isNumericValid = numeric.isNumeric;
String alphanumeric = 'abc123';
bool isAlphanumericValid = alphanumeric.isAlphanumeric;
String base64 = 'aGVsbG8gd29ybGQ=';
bool isBase64Valid = base64.isBase64;
String integer = '12345';
bool isIntValid = integer.isInt;
String float = '123.45';
bool isFloatValid = float.isFloat;
String hex = '1f';
bool isHexValid = hex.isHexadecimal;
String hexColor = '#ff0000';
bool isHexColorValid = hexColor.isHexColor;
String lower = 'hello';
bool isLowerValid = lower.isLowercase;
String upper = 'HELLO';
bool isUpperValid = upper.isUppercase;
String divisible = '10';
bool isDivisibleValid = divisible.isDivisibleBy(2);
String length = 'hello';
bool isLengthValid = length.isLength(3, 6);
String byteLength = 'hello';
bool isByteLengthValid = byteLength.isByteLength(3, 10);
String uuid = '550e8400-e29b-41d4-a716-446655440000';
bool isUuidValid = uuid.isUUID();
String date = '2023-05-17';
bool isDateValid = date.isDate;
String afterDate = '2024-01-01';
bool isAfterValid = afterDate.isAfter('2023-12-31');
String beforeDate = '2023-01-01';
bool isBeforeValid = beforeDate.isBefore('2024-01-01');
String inList = 'apple';
bool isInValid = inList.isIn(['apple', 'banana', 'cherry']);
String creditCard = '4111111111111111';
bool isCreditCardValid = creditCard.isCreditCard;
String isbn = '978-3-16-148410-0';
bool isIsbnValid = isbn.isISBN();
String json = '{"name": "John"}';
bool isJsonValid = json.isJson;
String multibyte = '你好';
bool isMultibyteValid = multibyte.isMultibyte;
String ascii = 'Hello';
bool isAsciiValid = ascii.isAscii;
String fullWidth = 'Hello';
bool isFullWidthValid = fullWidth.isFullWidth;
String halfWidth = 'Hello';
bool isHalfWidthValid = halfWidth.isHalfWidth;
String variableWidth = 'Hello';
bool isVariableWidthValid = variableWidth.isVariableWidth;
String surrogatePair = '𐍈';
bool isSurrogatePairValid = surrogatePair.isSurrogatePair;
String mongoId = '507f1f77bcf86cd799439011';
bool isMongoIdValid = mongoId.isMongoId;
// Using Sanitizer Extensions
String dateStr = '2024-05-18';
DateTime? parsedDate = dateStr.toDate();
String floatStr = '123.45';
double parsedFloat = floatStr.toFloat();
String intStr = '123';
int parsedInt = intStr.toInt();
String boolStr = 'true';
bool parsedBool = boolStr.toBoolean();
String trimStr = ' hello world ';
String trimmedStr = trimStr.trim();
String ltrimStr = ' hello';
String ltrimmedStr = ltrimStr.ltrim();
String rtrimStr = 'hello ';
String rtrimmedStr = rtrimStr.rtrim();
String whitelistStr = 'abcdef';
String whitelistedStr = whitelistStr.whitelist('abc');
String blacklistStr = 'abcdef';
String blacklistedStr = blacklistStr.blacklist('abc');
String stripLowStr = 'hello\u0000world';
String strippedLowStr = stripLowStr.stripLow();
String escapeStr = '<div>"Hello"&</div>';
String escapedStr = escapeStr.escape();
String normalizeEmailStr = 'Example+test@gmail.com';
String normalizedEmail = normalizeEmailStr.normalizeEmail();
}