web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to limit Textbox to enter 5 digits numeric only not alphabets using Javascript mscrm

(0) ShareShare
ReportReport
Posted on by 485

How to limit Textbox to enter 5 digits numerics only not alphabets using Javascript mscrm 2016?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this , below code should work  but I would suggest replace the the keypress method with dynamics CRM OOB method addOnKeyPress .

    https://community.dynamics.com/crm/b/mscrmcustomization/archive/2016/10/24/keypress-methods-in-ms-crm-2016

           //Add the code in web resource and load the webresource in the page 
    
            $("#new_Fax").keypress(function (event) {
                var charCode = event.keyCode;
                var obj = event.target;
    
                if (charCode < 48 || charCode > 57)
                    return false;
                else
                    return true;
    
            });
    
            //Register the function in onchange of field
    
            function OnChangeFax() {
                var FaxNo = Xrm.Page.getAttribute("new_Fax").getValue();
                if (FaxNo != null && FaxNo != undefined) {
                    if (FaxNo.length < 5) {
                        Xrm.Page.getControl("new_Fax").setNotification("Fax should be atleast 5 digits.", 'ERROR', 123);
                        Xrm.Page.getAttribute("new_Fax").setValue(null); } else { Xrm.Page.getControl("new_Fax").clearNotification(); } } }
  • Mohsin Ali Profile Picture
    3,634 on at

    Instead of creating simple textbox and limiting it using javascript, I would recommend you to create whole number field with following settings:

    Limiting-whole-number.PNG

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    whay don't you use the OOTB field type und choose number type and limit to 5 digits?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans