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

Notifications

Announcements

No record found.

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 483

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans