Edit Field Validation - Use of the native string.find() Lua Function
Hi,
I have an edit field in which I want to be validated immediately upon change. I ONLY want to accept alphanumeric characters (a-z and 0-9). I have tried this many ways, but have failed to get it exactly as I want it. First I tried Sample Code A, but that line of code fails because combination strings that contain the alphanumeric characters and a special character like the pound sign (#), will validate (Example: "hello1#"). I tried Sample Code B, but that isn't 100% what I want because if you were to add a character that isn't available on the keyboard, such as the copyright symbol or the trademak symbol. Can someone help me, please? Thank you.
Sample Code A:
interface:edit_field {
value = bind { key = 'new_table', object = properties },
fill_horizontal = 1,
immediate = true,
validate = function (interface, value)
if string.find(value, "[a-z%d]") then
return true, value, "good"
else
return false, value, "failed"
end
end
},
Sample Code B:
interface:edit_field {
value = bind { key = 'new_table', object = properties },
fill_horizontal = 1,
immediate = true,
validate = function (interface, value)
if string.find(value, "[~!@#$%^&*()_+`-={}|\%[%]:\";'<>?,./]") then
return false, value, "failed"
else
return true, value, "good"
end
end
},