You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chihpeng Lin <ch...@yahoo.com> on 2005/12/16 08:26:44 UTC
Validate max length of non single byte string (eg. Chinese characters)
I am a newbie of Tapestry.
I looked up the API of StringValidator.
It says:
Simple validation of strings, to enforce required, and minimum length (maximum length is enforced in the client browser, by setting a maximum input length on the text field).
What if the string is a non single byte string?
For example a Chinese UTF8 string which takes 3 bytes.
We can use maxlength in input object to limit string length.
It causes problems when it is inserted into database.
Do we have a validator which can check the max length in bytes of a string?
Thanks.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: Validate max length of non single byte string (eg. Chinese characters)
Posted by Paul Cantrell <ca...@pobox.com>.
Note that a string has no single well-defined length in bytes -- it
depends on the encoding. This hypothetical validator would thus need
to take an encoding as a parameter, and you'll have to make sure it
matches your DB's encoding. Be careful! It's a sticky problem.
That said, it would be a useful thing to have in contrib if properly
written.
Cheers,
Paul
On Dec 16, 2005, at 1:26 AM, Chihpeng Lin wrote:
> I am a newbie of Tapestry.
>
> I looked up the API of StringValidator.
>
> It says:
>
> Simple validation of strings, to enforce required, and minimum
> length (maximum length is enforced in the client browser, by
> setting a maximum input length on the text field).
>
> What if the string is a non single byte string?
> For example a Chinese UTF8 string which takes 3 bytes.
> We can use maxlength in input object to limit string length.
> It causes problems when it is inserted into database.
>
> Do we have a validator which can check the max length in bytes of
> a string?
>
> Thanks.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Validate max length of non single byte string (eg. Chinese characters)
Posted by Kent Tong <ke...@cpttm.org.mo>.
Chihpeng Lin <chihpeng_lin <at> yahoo.com> writes:
> In Firefox, it displays Chinese message (zh_TW) in Tapestry's validator, but
> it displays English message (en_US) in my own validator.
>
> The most wierd thing is that my validator works correctly in IE6. It
> displays Chinese message just like what Tapestry's validators do.
Check the preferred languages setting in FireFox. Make sure it is
listing zh-tw at the top instead of zh.
--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Validate max length of non single byte string (eg. Chinese characters)
Posted by Chihpeng Lin <ch...@yahoo.com>.
Thank you very much.
I've created a validator to check the byte length of a string.
It's not too difficult to create a validator in server side.
I haven't figured out how to create a client side validator.
Don't know how to integrate javascript into the validator yet.
But I have a problem when displaying the error message of my own validator.
I prepared both English and Chinese message property files (en_US and zh_TW).
The language of My OS is traditional Chinese.
In Firefox, it displays Chinese message (zh_TW) in Tapestry's validator, but it displays English message (en_US) in my own validator.
The most wierd thing is that my validator works correctly in IE6. It displays Chinese
message just like what Tapestry's validators do.
Regards,
Chihpeng Lin
Kent Tong <ke...@cpttm.org.mo> wrote:
Chihpeng Lin yahoo.com> writes:
> Do we have a validator which can check the max length in bytes of a string?
Not that I know of. But you can create your own. BTW, for Tapestry 4
you should use the validators like MaxLength, MinLength and others
in the org.apache.tapestry.form.validator package, not those in
the org.apache.tapestry.valid package.
--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: Validate max length of non single byte string (eg. Chinese characters)
Posted by Kent Tong <ke...@cpttm.org.mo>.
Chihpeng Lin <chihpeng_lin <at> yahoo.com> writes:
> Do we have a validator which can check the max length in bytes of a string?
Not that I know of. But you can create your own. BTW, for Tapestry 4
you should use the validators like MaxLength, MinLength and others
in the org.apache.tapestry.form.validator package, not those in
the org.apache.tapestry.valid package.
--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org