user3201763
user3201763

Reputation: 1

extjs textfield replace string format

I am working on extjs.

I have created extjs textfield telephone number and i am entering telephone number in that field.

I have done some validation for this field also:

regex: /^\+{1}([1-9]){2}\-{1}([0-9]){3}\-{0,1}([0-9]){3}\-([0-9]){4}$/i;

telephone number format : +91-8010562345 or +91-80105-62345 some other combinations are also working fine.

but what i need is when i enter telephone number

ex: 8010562345

should be displayed in the following format

ex:+91-80105-62345

and i am stuck in this part how to call this function in extjs which will replace entered string to above format

Upvotes: 0

Views: 1443

Answers (1)

Sujith PS
Sujith PS

Reputation: 4864

You can use the following code :

var s="8010562345";
var rep=s.match(/\d{10}/);
var rep=rep[0].replace(/(\d{5})(\d{5})/,function(first, second,third) {
    return "+91-"+second+"-"+third;
});

alert(rep);

Upvotes: 1

Related Questions