0

I am trying to develop one app in which I need one registration page. How should I apply validation in that for phone numbers and e-mail ? Please somebody help me

BB10
  • 9
  • 2

1 Answers1

2

You can place validation in your TextFields as follows:

TextField {
    id: myTextField
    hintText: "Flight number"
    inputMode: TextFieldInputMode.NumbersAndPunctuation
    validator: Validator {
        mode: ValidationMode.Immediate
        errorMessage: "Please enter only numbers for this field"
        onValidate: { 
            var valNumeric = /^[0-9 -]+$/i; //Numbers, including space and minus/dash                       
            if (valNumberic.test(parent.text)) {
                state = ValidationState.Valid;
            } else {
                state = ValidationState.Invalid;
            }
        }
    }
}

You can set the inputMode to something such as NumbersAndPunctuation or Email and that will affect the keyboard. Then in the onValidate you can compare the parent.text with a regex expression or in any other way you wish. Setting ValidationState to Invalid will show a validation error with the message you specify in errorMessage.

hyarion
  • 2,251
  • 2
  • 17
  • 28