Validate pin codes or phone no.s

I have one doubt
i want to validate the some field in my form such as pincode ,phone number ....
wheather the pincode exceed 6 digit i need to get error and phone num  exceed 10 or 12
i need to get error message...
For this validation what code we have to

please reply