Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

How to: Validate special characters?

Posted on by 371

How to: Validate special characters in a filed that are not allow only alpha numeric value it accepts 

Categories:
  • vinaytak Profile Picture
    vinaytak 371 on at
    RE: How to: Validate special characters?

    @André Arnaud de Calavon...lowercase characters are allowed if i use the code i have wriiten and i agree with all the suggestion u said to me..and i note also to use more and more the regular expression also....

  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,524 Super User 2024 Season 2 on at
    RE: How to: Validate special characters?

    Hi Vinay,

    Is your question answered? If so, mark the replies that helped you.

    I want to make one additional note: The approach using regular expressions and strContains should be considered. Or you try to find some illegal characters (strContains), but the list might be incomplete. E.g. the character "o/oo" (Can't find it on  my keyboard right now) is not listed, so allowed. I haven't tried the suggestion from Crispin, so I can't comment if the code should be correct or not.

    Using regular expressions you tell which values are allowed. Also here you can have an incomplete list. In your example you used "A-Z 0-9". This is allowing capitals only. So lowercase characters are not allowed here.

    Regular expressions are very powerful. Last week we defined a formula to check a string field for a valid entered date, including check on days per month and a leap year.

  • Verified answer
    vinaytak Profile Picture
    vinaytak 371 on at
    RE: How to: Validate special characters?

    it done successfully after writing code in table method

    public boolean validateWrite()

    {

       boolean ret;

       TextBuffer txt = new TextBuffer();

       ret = super();

       txt.setText(this.teachername);

       txt.regularExpressions(true);

       if (txt.find("^[A-Z 0-9]+$"))

       {

           ret = true;//info("string contains only numbers");

       }

       else

       {

           this.teachername="";

           throw error(" Conatin the Special Character");

       }

       return ret;

    }

  • vinaytak Profile Picture
    vinaytak 371 on at
    RE: How to: Validate special characters?

    @Crispin John Augustine... I already done this also but not working donot the reason why the code is not restricted.. any special char in.....is there i also tried the txt buffer method but not working........

  • vinaytak Profile Picture
    vinaytak 371 on at
    RE: How to: Validate special characters?

    @Crispin John Augustine .... it doesnt throw any error also when i am done written it can easily move to the nxt field

  • vinaytak Profile Picture
    vinaytak 371 on at
    RE: How to: Validate special characters?

    i have written the code in the table

    public boolean validateField(FieldId _fieldIdToCheck)

    {

       String30        teachername;

       boolean ret;

       ret = super(_fieldIdToCheck);

       if(ret)

       {

           switch (_fieldIdToCheck)

           {

                case fieldNum (Validationtale,teachername):

                if(strContains(teachername,"!@#$%^&*()_+=-[{]};:',<.>/?/-*+"))

           {

               Box::info("Special Character Is not Allowed ");

                  return checkFailed(strFmt("Invaild characters"));

                  }

                    else

                       {

                       break;

                       }

           }

       }

    return ret;

    }

    but in form they are accepting the special charc....

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans