Many peoples validate the Form for numbers using the property/widget of TextFormField() widget like keyboardType: TextInputType.number But I have a question that can we validate the Form only to prevent the Alphabets and punctuation marks from the Form and keeps the text of FormFiled String (numbers) ? is It possible ? If you have any logic for this please share it.
CodePudding user response:
TextField had inputFormatter. Just add this line inside the text field widget
inputFormatters: <TextInputFormatter>.
[WhitelistingTextInputFormatter.digitsOnly], // Only numbers are allowed
CodePudding user response:
Even if the keyboardType
property is set to TextInputType.phone
the text of the form field will be string
and not num
.
For further validation, use the validator
property.