Hi,
I have a phone field that is set to 11 digits but accepts any characters entered. How can I set the field to only accept digits and not text or special characters?
Hi,
I have a phone field that is set to 11 digits but accepts any characters entered. How can I set the field to only accept digits and not text or special characters?
Hi,
The Javascript which I have shared already tested , you can go with this without any problem, and don't forget to verify the answers.
Thank you all for your responses. I'll hopefully find out if the javascript has done the job in the near future.
Hi JustLearning,
I agree with Ravi that the most appropriate method is to use JavaScript and regular expression to limit the text.
If you recreate the Mobile Phone field as a whole number field, it is not suitable for 11 digits.
Because the maximum value of whole number field is 2,147,483,647, does not match the range of 11 digit phone numbers.(0~99,999,999,999)
And if the mobile phone starts with a few 0, the first few 0 will be deleted. E.g. 05101234567->5101234567
So the best way is to use JavaScript and regular expression.
Hope this helps.
Best Regards,
Lu Hao
Hi,
As suggested by Goutam above, you will need to use JS to restrict the number. The code share should work for you. You can refer the below article if you are not familiar with JS or how to use.
neilparkhurst.com/.../javascript-basics
Hope this helps.
Hi JustLearning,
If you recreate the Mobile Phone field as a whole number field then the field will only accept integer values (Numbers).
Hi ,
Try with this -
// Add below functions in your JS web resource // Register only onLoadEvents function in the form onload function onLoadEvents() { Xrm.Page.getControl('mobilephone').addOnKeyPress(AllowOnlyNumbers); } function AllowOnlyNumbers() { var phoneNo = Xrm.Page.getControl("mobilephone").getValue(); phoneNo = phoneNo.replace(/\D/g, ''); Xrm.Page.getAttribute('mobilephone').setValue(phoneNo); if (phoneNo.length == 11) { var formattedPhone = phoneNo.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3'); Xrm.Page.getAttribute('mobilephone').setValue(formattedPhone); } }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156