Validation using angularjs with custom directives


I am validating a form using angularjs and need to write custom directive for validating usa telephone format(111-111-1111) .When user leaves the telephone text box and if matches the pattern then it automatically show as 3 chunks like above.And also when I retrieve data from server it should display as 3 chunks.I need sample code using angularjs.

Thanks in adavance

Hi, @ksd07 can you please paste what you need in here:
In my opinion, i think you should have a function use regex to check out your telephone format. Below is my code:

var re = /^[0-9]{3}-[0-9]{3}-[0-9]{4}$/; 
var str = '123-123-1234';
var m;
while ((m = re.exec(str)) != null) {
    if (m.index === re.lastIndex) {
    // View your result using the m-variable.
    // eg m[0] etc.

Test pattern in here:
First: create a function in factory or external function.
Second: bind event after you submit or typing. Using regex to check if it is avaiable.
Third: if the format is avaiable get data from server by calling a factory handle getting data.

Thank you.But I am looking for custom directive using angularjs

You can use regex in your custom controller directive for checking data. But getting data from controller? I don’t think it is a good idea