I have three text fields called home phone,work phone and mobile phone. i need to do validation and number formatting for these fields. Below shown is the condition.

The home phone and work phone text fields should not accept more than 10 digits and less than eight digits. The fields should accept only numbers. The format of the numbers should be 
xxxx-xxxx(if 8 digits)
xx-xxxx-xxxx(if it is 10 digits)

The Mobile Phone number field should not accept more than 10 digits. The fields should accept only the numbers. The format of the numbers should be 
xxxx-xxx-xxx

I am not sure how to achieve this. Please help me.