>>Do you know what is wrong in my implementation and what would be the best way to fix it?
>>
>
>Move the code to the textbox Keypress event and use nodefault if space is entered.
>
>Like
>
>
>IF this.lNoSpacesAllowed and nKeyCode=32
>NODEFAULT
>ENDIF
>
Though this only prevents entering spaces. But, unless the previous value is a varchar and has length of zero, it's most probably padded with spaces. The user can click in the middle of these spaces, or just rightarrow over them and still have spaces.
I think that, in addition to this, somewhere in .lostfocus() or .valid(), some cleanup would be required:
this.value=chrtran(this.value, " ", "")
Possibly in the .gotfocus() as well - because if this is an observed problem, then it already happened before, and there are such values in the table. A retroactive cleanup may also be needed, depending on how strict the requirement is.