How do i format or create a UITextField (using Xamarin/C#) which allows phone number entry as "(xxx)xxx-xxxx"
The parentheses and the hyphen can be dynamic or static. Not very rigid on that. I could create three different UITextFields for the 3-part phone and have labels for "(", ")", and "-";but that doesn't look like a good way of doing this. Would rather do it correctly than hack it.
Any suggestions or ideas? There must be a better way. I found this: UITextField for Phone Number
but i don't understand objective-c. Maybe someone can help translate, if that is the solution ie I have the regex part covered.
Depends on your specific requirements:
To accomplish either of the above scenarios, all you need to do is subscribe to the appropriate event and perform formatting logic.
For scenario 1: Subscribe to the ValueChanged
event on the UITextField
. This event will be fired everytime a character is added or removed. Now you can define your code to format the phone number as the user is typing
For scenario 2: Subscribe to the EditingDidEndOnExit
event on the UITextField
. This event will be fired one editing has completed and the text field is no longer in focus. Now you can define your code to format the phone number here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.