vformfield

Creator: coderz1093

Last updated:

0 purchases

vformfield Image
vformfield Images
Add to Cart

Description:

vformfield

Validation Rules for Form Fields #
validation rules that can be used to validate form fields in Flutter applications.
[Screenshot .]
Getting Started #
To use this package, add vformfield as a dependency in your pubspec.yaml file.
Usage #
create username VFormField #
class UserName extends VFormField<String> {
UserName({required super.value}) : super();
}

PasswordText passwordText = PasswordText(
value: '',
rulebuilder: () => [
NotEmptyRule(),
RegExRule(
builder: (generator) => generator
.addGroup(
builder: (group) =>
group.addRange(0, 9, count: 3).isCamelCase(),
)
.endsWith('ly'),
errorRegex: 'error'), //121aAly
],
);

UserName usernameText = UserName(
value: '',
rulebuilder: () => [
NotEmptyRule(),
RegExRule(
builder: (generator) => generator
.contains('@')
.endsWith([".ly", ".com"])
.maxLength(15)
.minLength(5),
errorRegex: 'error'),
],
);
copied to clipboard
Custom validation regular expression patterns: #
dart
usernameText.addRule(
RegExRule(
builder: (generator) => generator.contains('@')
.endsWith([".ly", ".com"])
.maxLength(15)
.minLength(5),
errorRegex: 'الرجاء ادخال ايميل صالح'),
).addRule(
RegExRule(
pattern: example another rule,
errorRegex: 'example another message'),
).addRule(
RegExRule(
pattern: example another rule,
errorRegex: 'example another message'),
);
phoneNumberText
.addRule(RegExRule(
builder: (generator) => generator.minLength(8),
errorRegex: 'minLength'))
.addRule(RegExRule(
builder: (generator) => generator.contains('@').endsWith(5),
errorRegex: 'miss @ and must end with 5'))
.addRule(RegExRule(
builder: (generator) => generator.maxLength(15),
errorRegex: '> 5'));
copied to clipboard
use regular expression patterns: #

phoneNumberText.addRule(RegExRule(
builder: (generator) => generator.addGroup(
builder: (group) => group.startsWith("00218").flowingBy(
[92, 91], //[1,2] or number 1 or char A
count: 2,
).addRange(0, 9, count: 7))
.maxLength(14),
errorRegex: 'رقم الهاتف غير صالح')
.addRule(
RegExRule(
pattern: example another rule,
errorRegex: 'example another message'),
).addRule(
RegExRule(
pattern: example another rule,
errorRegex: 'example another message'),
));


TextFormField(
obscureText: phoneNumberText.obscureText,
validator: phoneNumberText.validator,
initialValue: "",
onChanged: (value) {
phoneNumberText.validator(value);
setState(() {});
},
decoration: InputDecoration(
labelText: 'Phone Number',
errorText: phoneNumberText.errorMessage,
),
),
copied to clipboard
USE BUILDER #
Wrap Your widget with Builder: value, message, obscure
passwordText.builder(
builder: (context, value, message, obscure) =>
TextFormField(
obscureText: passwordText.obscureText,
validator: passwordText.validator,
initialValue: "",
onChanged: (value) {
passwordText.validator(value);
},
decoration: InputDecoration(
labelText: 'Password',
errorText: passwordText.errorMessage,
suffixIcon: IconButton(
icon: Icon(
passwordText.obscureText
? Icons.visibility
: Icons.visibility_off,
color: Theme.of(context).primaryColorDark,
),
onPressed: () {
passwordText.setobscures();
},
),
),
),
),

copied to clipboard
Create Custom validation rules #
can be created by extending the ValidationRule class:
class CustomRule<T> extends ValidationRule<T> {
CustomRule()
: super(
validator: (value) {
if (value == null || value.isEmpty) {
return 'Value is required';
}
// Custom validation logic here
return null;
},
errorMessage: 'Value is invalid',
);
}
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.