Restricting Characters in Input

Hello,

 

I have an issue where an ampersand (&) is put into a text box by the user, and it returns an error because this is a special character for XML. What are your recommendations for restricting this character or replacing it with & within the string? Can I use LUA to search the input string and replace it? What would be the syntax for that?

Have more questions? Submit a request

1 Comments

  • 0
    Avatar
    Sebastian.Woodland

    I've had luck accomplishing this in lua using the gsub function (string.gsub(myinput,'&','&')):

    http://www.lua.org/pil/20.1.html

    Basically you'd probably have to do something like this:

    do

    -- get the value of your input control

    local myinput = thisview:getControl("myinputcontrol"):getValue()

    -- set the value of your input control to a new string with & replaced with &
    thisview:getControl("myinputcontrol"):setValue(string.gsub(myinput,'&','&'))

    end

    And you'll probably want to do this on the submit event in your case, but if you put it on the on change event for the control it will actually make those changes as they type.

     

    Hope that helps!

    -Seb

Please sign in to leave a comment.
Powered by Zendesk