This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Check for special characters.

 
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am retrieving name value from jsp:use bean and displaying it in jsp page.
Now I do need a small javascript processing like displaying name in some format like (lastname,first name) or otherwise , hence, for that I need to manipulate with the string in javascript and need to take care of special character's which can be encountereed in names.
Right now I m checking for every possible character..can i have a generic check ?
Thanks in advance.
Varun.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to JavaScript...
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, now what do you want to happen exactly?? I do not know what needs to bedone exactly. Do you want it replaced?? Do you want it alerted?? do you want it to change to html code?? ETC.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ian,
I am displaying the names in "jsp page" which are hyperlinked and clicking on them gives details of those names in a pop-up.Now in "jsp page" names are displayed using jsp tags so there is no problem comming but when calling the javascript function e.g. javascript:functionname('<%=name%>')
it is giving javascript error.Through that function i m calling the pop-up, but the function is not getting called in cases when <%=name%> contains arabic or some other weird character.
Thanks in advance.
Varun
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my guess is the javascript string literal contains either a single or double quote which is short circuiting the string.For example the string:'john O'Reilly' would become -john O-.This would cause a javascript error during the html page loading.The string "john O'Reilly" would not short circuit.You can use the backslash to escape quotes or other special characters.
'john O\' Reilly' is a valid string.
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
there is a funny thing, that crossed my mind
If you don't want to write any string parsing/replacing functions, you could have the following
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Charlie,
My page may contains 10 to 1000 names and chances are 1 out of 100 that I will get an non-ascii or arabic character .So for such a small possibility will it be logical to check every name and put a escape character IF it contains any special characcter.
Or do we have any javascript or java method to find out if a particular string contains any non-ascii character.
I also tried out a way(may sound funny),instead of passing the name I passed to the bytecode of that string upto the pop-up but at pop-up i failed to get back the string representation of that byte code.
 
Charlie Sturman
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do the non-alpha-numeric escape formatting of the javascript strings on the server in the jsp code.
If the bad string gets to the browser there is no way to fix it via javascript.Kinda like a compile error.
I do not yet know jsp/servlets.I am pretty familiar with the msft IIs asp server.Based upon this experience I will say it should be easy to escape the mis behaving char codes.Look for help in the jsp/servlet forum.
 
Charlie Sturman
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another example using Yuriy's insite:

[ July 14, 2002: Message edited by: Charlie Sturman ]
[ July 14, 2002: Message edited by: Charlie Sturman ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
A possible soln to your problem using regular Expressions --
function getSOP(form){
str = form.str.value
var regexpr =/[^A-Za-z0-9]/;
result= regexpr.test(str)
alert(result)
}
U could try calling this code where variable 'str' contains the string to be checked for Ascii characters. It will return/alert TRUE is the string does contain one/more Ascii character(s).
All the best :-)
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you want to play with a byte code,
string, that you get from your java should contain hexadecimal code of unicode characters.
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All,
Just find out that jdk1.4 has a new api as RegEx which can help me out in this.
Thanks again.
Varun.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic