Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Special chars(~,^) validation in Smart Client

    Hi,

    I am posting this question here.. Because I didn't find a new thread option..

    When I use the RegExp [\~\^] or /[\~\^]/ as input for the “expression” attribute of “regexp” validatortype, the validation is not working. And the screen always gives error for any input chars with or without the mentioned special characters.

    <field name="II4_DOC_HEADER" type="text" >
    <validators>
    <validator type="regexp" expression="[\~\^]" errorMessage="Value must not contain either ^ or ~"></validator>
    </validators>
    </field>

    To check if the validatortype “regexp” works fine or not, have tested for the expressions [0-9] or [A-Z] and they both are working fine for positive and negative scenarios. However they do not work for the validation of ^ or ~.

    <field name="II4_DOC_HEADER" type="text" >
    <validators>
    <validator type="regexp" expression="[0-9]" errorMessage="Value must contain only numeric </validator>
    </validators>
    </field>

    Below is the javascript function which alerts whenever the input string contains ~ or ^ chars. The RegExp used below is working fine.

    <body>
    <script>
    function validate(){
    //var inp = "1ab@#cdf~e^";
    var inp = document.getElementById('in').value;
    if (RegExp(/[\~\^]/).test(inp)) {
    alert("true");
    return true;
    }
    else
    {
    alert("false");
    return false;
    }
    }
    </script>
    <input type="text" id="in" />
    <button name="clickbtn" onclick="validate()"> Click</button>
    </body>

    However, able to achieve the special characters validation for ~ or ^ by using below validatortype “contains”.

    <field name="II4_DOC_HEADER" type="text" >
    <validators>
    <validator type="contains" substring="~" errorMessage="Value must not contain ~ character"></validator>
    <validator type="contains" substring="^" errorMessage="Value must not contain ^ character"></validator>
    </validators>
    </field>

    We would like to know if it is possible to make the regexp work for the validation of ~ and ^.

    Please do the needful..

    Thanks in Advance.

    #2
    Use the "New Thread" button in the message list to start a new thread. We've moved your post to a new thread.

    The "expression" property of a regexp validator indicates *what characters are allowed*. You are trying to use it as though it means what characters are *not* allowed.

    Comment


      #3
      Reg: Is there any way to do the validation like not to allow some characters

      Hi,

      Thanks for the response.

      If the regExp is used to allow the characters, Then what do i need to use to not allow the characters in smart Client.

      I need an information like.. What are the characters which smart client doesn't allow to enter in text box and text area?

      We are getting an SAX parse exception if we use ~ and ^ in my text or text area.

      So, What would be the solution... to solve this error..

      Thanks

      Comment


        #4
        This is standard regular expression usage, not anything specific to SmartGWT. In regular expressions, use "^" to invert a character class - see any regular expression reference for details.

        Comment

        Working...
        X