Skip to main content

Notifications

Microsoft Dynamics AX forum
Answered

How to: Validate special characters?

Posted on by 367

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

Categories:
  • vinaytak Profile Picture
    vinaytak 367 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
    Andre Arnaud de Calavon Profile Picture
    Andre Arnaud de Cal... 283,428 Super User 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 367 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 367 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 367 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 367 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....

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

    i have a simple field "name" edt  is string 30 ...i have a simple form in that name field sholud not allow any special char.. so i write the validate method in table but its not working they are accepting all the character .. can u give me a example regrading this how to use it....

  • Suggested answer
    Andre Arnaud de Calavon Profile Picture
    Andre Arnaud de Cal... 283,428 Super User on at
    RE: How to: Validate special characters?

    Hi Vinay,

    You can solve it with coding. You can call Regular Expressions. How to use this can be found in an example: WinAPI::isFileNameValid OR SysEmailDistributor::validateEmail

    If you need to know more about regular expressions, you can learn on this site: http://regexr.com/

  • Suggested answer
    Basheer17 Profile Picture
    Basheer17 2,720 on at
    RE: How to: Validate special characters?

    Define all special characters in a list. Use strContains function by iterating through the list.

  • sohaibcheema Profile Picture
    sohaibcheema 46,590 User Group Leader on at
    RE: How to: Validate special characters?

    Hi,

    you can make use of Regex expressions(System.Text.RegularExpressions.Regex). Have a look at an example shown in an old post.

    community.dynamics.com/.../171654

    additionally if you will search about regex expressions, you can find lot of material on it.

Helpful resources

Quick Links

Contextual content recommendations & SharePoint Q&A

Instantly access relevant sales materials…

Beyond the DRA Cloud Label Printing

Explore cloud-based label printing within Dynamics 365…

HR Infrastructure Customer merge

Important considerations for HR Customer migrations…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,428 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,784 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,142

Featured topics

Product updates

Dynamics 365 release plans