473,224 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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
Jul 23 '05 #1
4 9403
Madha K wrote:
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.

<snip>

You're in the wrong 'group.

http://smjg.port5.com/faqs/web/js/javaisnotjs.html

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
the 'group where everyone may benefit.
Jul 23 '05 #2
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!
Jul 23 '05 #3


Madha K wrote:
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.
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.
1) How javascript can be used to restrict non-utf8 characters?
The script doesn't know about the encoding, a string is simply a
sequence of Unicode characters.
2) Using javascript how to find the lengh of a string having unicode
characters?
string.length
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.


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
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
On 07 Sep 2004 12:01:57 GMT, Mahda <Km**@yahoo.com> wrote:
Hi Stewart,
I doubt if you have really gone through my question.
He didn't really need to; you cross-posted a Javascript question to a Java
newsgroup. Stewart's post was merely pointing that out.
Please note that i dont want any help in java but want some javascript
help for client side validations.


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="return 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.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ying Huang-Isella | last post by:
I have a Javascript menu bar on top of each of my aspx pages. The menu bar would not display when I turn on SmartNavigation. I did some search on this newsgroup and found the answer to my problem...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
26
by: Patient Guy | last post by:
Has anyone written code that successfully manipulates binary file data using Javascript? It might---and in the case of doing I/O, will---make use of browser- specific functions (ActiveX/COM with...
1
by: Kenny Ho | last post by:
Hi, I have written the following schema that contains the XML signature: ----------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8" ?>...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
6
by: lists | last post by:
Hi all, I am trying to validate an XML file against an XSD schema file within a ..NET C++ program, but the validation doesn't seem to be occuring. My code is listed below. The validation...
0
by: tanish2k | last post by:
hi. I am using c#, visual studio 2003. I need to validate a xml file against schema which itself has 2 more schema imported under it. i have following 2 xsd files : xsd1 --->...
8
by: frohlinger | last post by:
Hi, I have a search textbox in my website. I validate the search string with a "white list" of allowed characters: if((/^+$/).test(theSearchWord) == false) { return; }
1
by: NamelessNumberheadMan | last post by:
I can't seem to get Struts 2 validations to work. I have been converting from Strust 1 to Struts 2. So far I've refactored all the code (for this particular module) on the back end, rewrote the jsp...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.