ios - UItextField Phone number formatting -


i have 3 text fields called home phone,work phone , mobile phone. need validation , number formatting these fields. below shown condition.

the home phone , work phone text fields should not accept more 10 digits , less 8 digits. fields should accept numbers. format of numbers should xxxx-xxxx(if 8 digits) xx-xxxx-xxxx(if 10 digits)

the mobile phone number field should not accept more 10 digits. fields should accept numbers. format of numbers should xxxx-xxx-xxx

i not sure how achieve this. please me.

i think can achieve doing following:

  1. capture text change event in uitextfield. add dashes after 4 characters, after 7 characters , on depending on format want.
  2. use regular expression validate entire string of numbers dashes. (eg: xxxx-xxxx format use '[0-9]{4}-[0-9]{4}')

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

visual studio - TFS will not accept changes I've made to a Java project -