Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Simple text field with minimum characters.

Posted on by 45

Hi everybody,

Im looking for a solution for my problem:

I want a simple text field in de contact entity, with a minimum AND Maximum characters lenght of 5.

now it is possible to specify a maximum. but not to indicate a minimum. The format of the form must be (days / months). So from 01-01 to 31-12. Preferably with the first two values ​​that can go up to 31 and the last two values ​​to 12. But just a minimum would solve a large part of the problem.

I understood that this might be possible through javascript in the onchange event?

If this is not recommended because it is too much work, then I would also like to hear that.

Regards,
Daimy Tamis

*This post is locked for comments

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Simple text field with minimum characters.

    Hi,

    This can be/ should be achieved by JS.  You can tweek the above suggested sample code as per your requirements.

    Hope this helps.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Simple text field with minimum characters.

    Hi Daimy ,

    I understand your problem , but unfortunately there is no way to define your specific business logic without code. You need to write JS code for that ,there is no other options .

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Simple text field with minimum characters.

    Hi Daimy Tamis,

    It can be done with On Change JavaScript. The rough process for creating the JavaScript is as follows.

    1. Create a JavaScript file that runs On Change of your simple text field.
    2. With the JavaScript code, retrieve the value of your simple text field, check its length, and prevent save of the field if it does not contain five or more characters.

    This is a basic example of a JavaScript function that can accomplish this.

    function FieldValidation(context)
    {
        var field = Xrm.Page.getAttribute("field").getValue();
        if(field.length < 5)   {
            Xrm.Utility.alertDialog("Please enter five or more characters in field");
            context.getEventArgs().preventDefault();
        }
    }

    However, it sounds like you are working with date values. Consider creating a Date and Time field before trying to solve this problem with JavaScript.

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    Temmy Wahyu Raharjo 2,914 on at
    RE: Simple text field with minimum characters.

    Hi,

    I think you can create Javascript and put onchange event on that attribute. Then you can use Regex or just use traditional way (split by '/', parseToInt to check if the value is int or not and check the length <= 5 or not).

    stackoverflow.com/.../regular-expression-for-two-digit-month-and-two-digit-day-only

    Is not to difficult and you can handle it using Javascript.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans