Javascript validation for UTF-8 chatacters

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Madha K

    Javascript validation for UTF-8 chatacters

    I am developing a web application that need to support UTF-8
    characters.
    For client side validations, can javascript be used to handle UTF-8
    characters.
    1) How javascript can be used to restrict non-utf8 characters?
    2) Using javascript how to find the lengh of a string having unicode
    characters?
    e.g: For a field Name on the form, there is a corrosponding field Name
    varchar2(10) in DB. Through my application when i try enter 10 normal
    (i.e A-Z) characters, JDBC smoothly updates the DB.
    But when my input has some 10 funny UTF8 characters, JDBC throws error
    "inserted value too large".
    Is there any javascript through which i can validate the input length
    agaist the DB field size.

    Thanks
    Madha
  • Stewart Gordon

    #2
    Re: Javascript validation for UTF-8 chatacters

    Madha K wrote:[color=blue]
    > I am developing a web application that need to support UTF-8
    > characters.
    > For client side validations, can javascript be used to handle UTF-8
    > characters.[/color]
    <snip>

    You're in the wrong 'group.



    Stewart.

    --
    My e-mail is valid but not my primary mailbox. Please keep replies on
    the 'group where everyone may benefit.

    Comment

    • Mahda

      #3
      Re: Javascript validation for UTF-8 chatacters

      Hi Stewart,
      I doubt if you have really gone through my question.
      Please note that i dont want any help in java but want some javascript
      help for client side validations.

      Please let me know if you have any idea about such javascript.

      Thanks



      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Martin Honnen

        #4
        Re: Javascript validation for UTF-8 chatacters



        Madha K wrote:
        [color=blue]
        > I am developing a web application that need to support UTF-8
        > characters.
        > For client side validations, can javascript be used to handle UTF-8
        > characters.[/color]

        Script engines in Netscape 4.06 and later and IE 4 and later and other
        modern browsers implementing the ECMAScript edition 3 standard can
        handle Unicode characters, internally I think UTF-16 is used as the
        encoding but in your HTML pages having the script the encoding doesn't
        matter, if you have a JavaScript string you have an Unicode string where
        each character has an Unicode character code.
        [color=blue]
        > 1) How javascript can be used to restrict non-utf8 characters?[/color]

        The script doesn't know about the encoding, a string is simply a
        sequence of Unicode characters.
        [color=blue]
        > 2) Using javascript how to find the lengh of a string having unicode
        > characters?[/color]

        string.length
        [color=blue]
        > e.g: For a field Name on the form, there is a corrosponding field Name
        > varchar2(10) in DB. Through my application when i try enter 10 normal
        > (i.e A-Z) characters, JDBC smoothly updates the DB.
        > But when my input has some 10 funny UTF8 characters, JDBC throws error
        > "inserted value too large".
        > Is there any javascript through which i can validate the input length
        > agaist the DB field size.[/color]

        As said, a JavaScript string is a sequence of Unicode characters, how
        that is stored on the server in a data base doesn't depend on how script
        on the client represents the string.
        And it doesn't make much sense to to client-side validation without
        server-side validation implemented first as JavaScript can be disabled
        or simply not being supported.



        --

        Martin Honnen

        Comment

        • Michael Winter

          #5
          Re: Javascript validation for UTF-8 chatacters

          On 07 Sep 2004 12:01:57 GMT, Mahda <Kmah@yahoo.com > wrote:
          [color=blue]
          > Hi Stewart,
          > I doubt if you have really gone through my question.[/color]

          He didn't really need to; you cross-posted a Javascript question to a Java
          newsgroup. Stewart's post was merely pointing that out.
          [color=blue]
          > Please note that i dont want any help in java but want some javascript
          > help for client side validations.[/color]

          Going back to your original post, Javascript always handles Unicode
          characters: strings are internally converted to Unicode sequences. The
          best form of input validation usually involves regular expressions that
          ensure the user follows some format. A length check is a simple comparison
          of the length property:

          var elems = document.forms['formName'].elements;
          if(elems['elementName'].value.length < comparison here >) {
          // do stuff
          }

          To validate a form when it's submitted, you would use something like:

          <form ... onsubmit="retur n validate(this)" >

          function validate(form) {
          var elements = form.elements;

          if(10 < elements['elementName'].value.length) {
          alert('Please limit your value to 10 characters.');
          elements['elementName'].focus();
          return false;
          }
          // More validation
          return true;
          }

          If the form field, elementName, had a value greater than 10 characters,
          the user would be notified and the form would not be submitted. The
          statement, return false, cancels the submission.

          Don't forget that you can attempt to limit the length of user input using
          the maxlength property. You should still check the value though, just to
          be safe.

          The final thing you might want to consider is whether your input data is
          being read properly by the server. If single Unicode characters are being
          broken up into multiple bytes for transmission, is the server using those
          bytes, or is it reforming the original characters? Not having dealt with
          Unicode input, I couldn't say whether this was a possibility or not.

          All that said, and this is important, you should not be relying on
          Javascript to validate your page. The server *must* validate input and
          should an error be found, respond with a page describing an error and
          allowing for its correction. Client-side validation should only be used to
          speed up the validation process and reduce server traffic. From what you
          describe in your original post, you don't seem to be doing this.

          [snip]

          Hope that helps,
          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          Working...