extjs - Regex is showing phone number as valid for 9 & 10 total digits when it should show valid for 10 digits only -



extjs - Regex is showing phone number as valid for 9 & 10 total digits when it should show valid for 10 digits only -

i using validate phone number.....it shouldbe of 10 digits , 1 time of 10 digits, remove reddish squiggly line , format in (xxx)xxx-xxxx in pattern. but, according validation, when finished writing 9 digits, shows number valid number , removes reddish squiggly line , when write 10th digit, formats in above pattern.

// custom vtype vtype:'phone' // vtype phone number validation ext.apply(ext.form.vtypes, { 'phonetext': i18n.validation.phonetext, 'phonemask': /[\-\+0-9\(\)\s\.ext]/, 'phonere': /^(\({1}[0-9]{3}\){1}\s{1})([0-9]{3}[-]{1}[0-9]{4})$|^(((\+44)? ?(\(0\))? ?)|(0))( ?[0-9]{3,4}){3}$|^ext. [0-9]+$/, 'phone': function (v) { homecoming this.phonere.test(v); } }); // function format phone number ext.apply(ext.util.format, { phonenumber: function(value) { var phonenumber = value.replace(/\./g, '').replace(/-/g, '').replace(/[^0-9]/g, ''); if (phonenumber != '' && phonenumber.length == 10) { homecoming '(' + phonenumber.substr(0, 3) + ') ' + phonenumber.substr(3, 3) + '-' + phonenumber.substr(6, 4); } else { homecoming value; } } }); ext.namespace('ext.ux.plugin'); // plugin format phone number on value alter ext.ux.plugin.formatphonenumber = ext.extend(ext.form.textfield, { init: function(c) { debugger; c.on('change', this.onchange, this); }, onchange: function(c) { debugger; c.setvalue(ext.util.format.phonenumber(c.getvalue())); }}); this.phone = { xtype: 'textfield', country: bedbath.registry.params.country, labelseparator: "", fieldlabel: i18n.label.phone+": <span style='color:red'>*</span>", name: "phone1re", ref: 'phone1re', id: 'phone1re', allowblank: false, vtype:'phone', plugins: new ext.ux.plugin.formatphonenumber() };

i dont know how showing valid 9 digits? can help me out? give thanks you.

your middle alternative allows 9 digits.

^(((\+44)? ?(\(0\))? ?)|(0))( ?[0-9]{3,4}){3}$

everything optional except lastly part, can 3-4 numbers repeated 4 times (this 9-12 digits)

if want create sure it's 10 characters , using type numbers (which appears are), work create 10 numbers possible space between right spots, alter lastly part like:

((?: ?[0-9]{3}){2} ?[0-9]{4})

in total this:

^(\({1}[0-9]{3}\){1}\s{1})([0-9]{3}[-]{1}[0-9]{4})$|^(((\+44)? ?(\(0\))? ?)|(0))((?: ?[0-9]{3}){2} ?[0-9]{4})$|^ext. [0-9]+$

debuggex demo

regex extjs extjs4 extjs4.1 extjs4.2

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -