473,327 Members | 2,118 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,327 software developers and data experts.

validating the string in ASP


Hi! i m new to this forum and need some help in ASP

how can i validate a string so that it have only the characters
of ASCII 32 to 91 and 93 to 122 ? Also if the string contains the
comma (,) the whole string should be converted inside the quotes ("")
i.e.

if the string is: example string, Ok
it should be: "example string, Ok"

--
asimrafi
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Mar 6 '06 #1
10 2476

asimrafi wrote:
Hi! i m new to this forum and need some help in ASP

how can i validate a string so that it have only the characters
of ASCII 32 to 91 and 93 to 122 ? Also if the string contains the
comma (,) the whole string should be converted inside the quotes ("")
i.e.

if the string is: example string, Ok
it should be: "example string, Ok"

--
asimrafi
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------


On the server side, use VBScript Regular Expressions:
http://msdn.microsoft.com/library/de...ting051099.asp

On the client side, use the Javascript version:
http://www.regular-expressions.info/javascript.html

--
Mike Brind

Mar 6 '06 #2
asimrafi wrote on 06 mrt 2006 in microsoft.public.inetserver.asp.general:

Hi! i m new to this forum and need some help in ASP

how can i validate a string so that it have only the characters
of ASCII 32 to 91 and 93 to 122 ? Also if the string contains the
comma (,) the whole string should be converted inside the quotes ("")
i.e.

if the string is: example string, Ok
it should be: "example string, Ok"


<% 'vbscript
dim a
a = "example "&vbcr&"stringX Ok"
response.write convertMe(a) & "<br>"

a = "example "&vbcr&"string, Ok"
response.write convertMe(a) & "<br>"

%>

<script language='jscript' runat='server'>
// 32-91 space-[ and 93-122 ]-z
function convertMe(s){
s = s.replace(/[^ -\[\]-z]/,'');
if (/,/.test(s)) s = '"'+s+'"';
return s;
}
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 6 '06 #3
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:
On the server side, use VBScript Regular Expressions:
http://msdn.microsoft.com/library/de...y/en-us/dnclin
ic/html/scripting051099.asp
Why this serversie preoccupation with vbscript?

Jscript regex is cleaner code.
On the client side, use the Javascript version:
http://www.regular-expressions.info/javascript.html


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 6 '06 #4

Evertjan. wrote:
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:
On the server side, use VBScript Regular Expressions:
http://msdn.microsoft.com/library/de...y/en-us/dnclin
ic/html/scripting051099.asp


Why this serversie preoccupation with vbscript?

Jscript regex is cleaner code.


Ermm... because I don't know Jscript? And I don't think I'm alone in
that among ASP coders. And anyway - VBScript does the job:

<%
dim i, strSearchOn, objRegExpr, objmatch, colmatches
i = 0
strSearchOn = "My Example String"
if instr(strSearchOn,",") then strSearchOn = """" & strSearchOn & """"
Set objRegExpr = new regexp
objRegExpr.Pattern = "[^\40-\133\135-\172]"
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
set colmatches = objRegExpr.Execute(strSearchOn)
for each objmatch in colmatches
if objmatch.value <> "" then
i = i + 1
End If
next
If i > 0 then
response.write "Validation Failed"
Else
response.write "Validation Passed"
End If
%>

If you mean by "cleaner code" there's less of it, that's true. But the
time taken to produce the above in VBScript was considerably less than
learning JScript just for use with RegEx, which seems to me to be a
huge investment in time for little gain - purely from my point of view
:-)

--
Mike Brind

Mar 6 '06 #5

Evertjan. wrote:
asimrafi wrote on 06 mrt 2006 in microsoft.public.inetserver.asp.general:

Hi! i m new to this forum and need some help in ASP

how can i validate a string so that it have only the characters
of ASCII 32 to 91 and 93 to 122 ? Also if the string contains the
comma (,) the whole string should be converted inside the quotes ("")
i.e.

if the string is: example string, Ok
it should be: "example string, Ok"


<% 'vbscript
dim a
a = "example "&vbcr&"stringX Ok"
response.write convertMe(a) & "<br>"

a = "example "&vbcr&"string, Ok"
response.write convertMe(a) & "<br>"

%>

<script language='jscript' runat='server'>
// 32-91 space-[ and 93-122 ]-z
function convertMe(s){
s = s.replace(/[^ -\[\]-z]/,'');
if (/,/.test(s)) s = '"'+s+'"';
return s;
}
</script>


How does the above deal with illegal characters such as ~ \ { } | ?

--
Mike Brind

Mar 6 '06 #6
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:

Evertjan. wrote:
asimrafi wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:
>
> Hi! i m new to this forum and need some help in ASP
>
> how can i validate a string so that it have only the characters
> of ASCII 32 to 91 and 93 to 122 ? Also if the string contains the
> comma (,) the whole string should be converted inside the quotes
> ("") i.e.
>
> if the string is: example string, Ok
> it should be: "example string, Ok"


<% 'vbscript
dim a
a = "example "&vbcr&"stringX Ok"
response.write convertMe(a) & "<br>"

a = "example "&vbcr&"string, Ok"
response.write convertMe(a) & "<br>"

%>

<script language='jscript' runat='server'>
// 32-91 space-[ and 93-122 ]-z
function convertMe(s){
s = s.replace(/[^ -\[\]-z]/,'');
if (/,/.test(s)) s = '"'+s+'"';
return s;
}
</script>


How does the above deal with illegal characters such as ~ \ { } | ?


Illegal in what sense?

They are perfectly legal under Netherlands jurisdiction. ;-)

Externally to the jscript part,
the function acts like a vbscript function.

Anyway, you can try, by putting the above script in an asp file.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 6 '06 #7

Evertjan. wrote:
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:

Evertjan. wrote:
asimrafi wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:

>
> Hi! i m new to this forum and need some help in ASP
>
> how can i validate a string so that it have only the characters
> of ASCII 32 to 91 and 93 to 122 ? Also if the string contains the
> comma (,) the whole string should be converted inside the quotes
> ("") i.e.
>
> if the string is: example string, Ok
> it should be: "example string, Ok"

<% 'vbscript
dim a
a = "example "&vbcr&"stringX Ok"
response.write convertMe(a) & "<br>"

a = "example "&vbcr&"string, Ok"
response.write convertMe(a) & "<br>"

%>

<script language='jscript' runat='server'>
// 32-91 space-[ and 93-122 ]-z
function convertMe(s){
s = s.replace(/[^ -\[\]-z]/,'');
if (/,/.test(s)) s = '"'+s+'"';
return s;
}
</script>

How does the above deal with illegal characters such as ~ \ { } | ?


Illegal in what sense?

They are perfectly legal under Netherlands jurisdiction. ;-)


There's an awful lot that's legal in the Netherlands that isn't
anywhere else :-P

In this case, however, I meant the characters deemed illegal in the OP.
Only strings that did not contain those characters (and some others)
were allowed - althought the OP didn't say what they wanted to do if
the string contained those characters....

Externally to the jscript part,
the function acts like a vbscript function.

Anyway, you can try, by putting the above script in an asp file.


I did try it. All it seemed to do was put quotes round strings
containing commas. It didn't seem to do anything with characters
outside the ascii range the OP wanted to avoid. Maybe I'm missing
something here?

--
Mike Brind

Mar 6 '06 #8
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:
>> <script language='jscript' runat='server'>
>> // 32-91 space-[ and 93-122 ]-z
>> function convertMe(s){
>> s = s.replace(/[^ -\[\]-z]/,'');
>> if (/,/.test(s)) s = '"'+s+'"';
>> return s;
>> }
>> </script>
>>
>
> How does the above deal with illegal characters such as ~ \ { } | ?
Illegal in what sense?

They are perfectly legal under Netherlands jurisdiction. ;-)


There's an awful lot that's legal in the Netherlands that isn't
anywhere else :-P

In this case, however, I meant the characters deemed illegal in the OP.

> how can i validate a string so that it have only the characters
> of ASCII 32 to 91 and 93 to 122 ?

I took that as having them deleted, as the output was not to be a
true/false, but a corrected string.
Only strings that did not contain those characters (and some others)
were allowed - althought the OP didn't say what they wanted to do if
the string contained those characters....


True, but see my "taking" above.
Externally to the jscript part,
the function acts like a vbscript function.

Anyway, you can try, by putting the above script in an asp file.


I did try it. All it seemed to do was put quotes round strings
containing commas. It didn't seem to do anything with characters
outside the ascii range the OP wanted to avoid. Maybe I'm missing
something here?


32-91 -> space-[
and
93-122 -> ]-z

s = s.replace(/[^ -\[\]-z]/,'')

they are replaced by an empty string, as I showed with the
vbCr = chr(13) example.

for testing purposes you could do:

s = s.replace(/[^ -\[\]-z]/,'?')

which would replace them with a "?".

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 6 '06 #9

Evertjan. wrote:
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:
>> <script language='jscript' runat='server'>
>> // 32-91 space-[ and 93-122 ]-z
>> function convertMe(s){
>> s = s.replace(/[^ -\[\]-z]/,'');
>> if (/,/.test(s)) s = '"'+s+'"';
>> return s;
>> }
>> </script>
>>
>
> How does the above deal with illegal characters such as ~ \ { } | ?

Illegal in what sense?

They are perfectly legal under Netherlands jurisdiction. ;-)


There's an awful lot that's legal in the Netherlands that isn't
anywhere else :-P

In this case, however, I meant the characters deemed illegal in the OP.

>> how can i validate a string so that it have only the characters
>> of ASCII 32 to 91 and 93 to 122 ?
I took that as having them deleted, as the output was not to be a
true/false, but a corrected string.
Only strings that did not contain those characters (and some others)
were allowed - althought the OP didn't say what they wanted to do if
the string contained those characters....


True, but see my "taking" above.
Externally to the jscript part,
the function acts like a vbscript function.

Anyway, you can try, by putting the above script in an asp file.


I did try it. All it seemed to do was put quotes round strings
containing commas. It didn't seem to do anything with characters
outside the ascii range the OP wanted to avoid. Maybe I'm missing
something here?


32-91 -> space-[
and
93-122 -> ]-z

s = s.replace(/[^ -\[\]-z]/,'')

they are replaced by an empty string, as I showed with the
vbCr = chr(13) example.

for testing purposes you could do:

s = s.replace(/[^ -\[\]-z]/,'?')

which would replace them with a "?".


I goddit. although I'm still not tempted to delve into Jscript
reference docs ;-)

--
Mike Brind

Mar 6 '06 #10

Evertjan. wrote:
Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general:
>> <script language='jscript' runat='server'>
>> // 32-91 space-[ and 93-122 ]-z
>> function convertMe(s){
>> s = s.replace(/[^ -\[\]-z]/,'');
>> if (/,/.test(s)) s = '"'+s+'"';
>> return s;
>> }
>> </script>
>>
>
> How does the above deal with illegal characters such as ~ \ { } | ?

Illegal in what sense?

They are perfectly legal under Netherlands jurisdiction. ;-)


There's an awful lot that's legal in the Netherlands that isn't
anywhere else :-P

In this case, however, I meant the characters deemed illegal in the OP.

>> how can i validate a string so that it have only the characters
>> of ASCII 32 to 91 and 93 to 122 ?
I took that as having them deleted, as the output was not to be a
true/false, but a corrected string.
Only strings that did not contain those characters (and some others)
were allowed - althought the OP didn't say what they wanted to do if
the string contained those characters....


True, but see my "taking" above.
Externally to the jscript part,
the function acts like a vbscript function.

Anyway, you can try, by putting the above script in an asp file.


I did try it. All it seemed to do was put quotes round strings
containing commas. It didn't seem to do anything with characters
outside the ascii range the OP wanted to avoid. Maybe I'm missing
something here?


32-91 -> space-[
and
93-122 -> ]-z

s = s.replace(/[^ -\[\]-z]/,'')

they are replaced by an empty string, as I showed with the
vbCr = chr(13) example.

for testing purposes you could do:

s = s.replace(/[^ -\[\]-z]/,'?')

which would replace them with a "?".


I goddit.... although I'm still not tempted to delve into Jscript
reference docs ;-)

--
Mike Brind

Mar 6 '06 #11

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

Similar topics

1
by: Brian Kedersha | last post by:
I found code for validating XML documents with the XML Schema cashed for rapid access. Example 3: Validating with XMLSchemaCache. ...
1
by: Christian | last post by:
Hi, I load an Xml-file "customers.xml" into a DataSet (works fine) but then how do I validate it against a schema (e.g. customers.xsd) ? my customers.xml: <?xml version="1.0"...
6
by: Robert Reineri | last post by:
Hello, New to the XML world and .NET. I have what I believe to be a simple problem, but I have read the .NET docs till I'm blue in the face and still can't locate a simple example of how to...
1
by: Andy | last post by:
I am having some trouble validating XML using the XmlValidatingReader. I have created some xml and used the visual studio to generate the schema. So I am confident that the xml and schema match. ...
2
by: Joris Janssens | last post by:
I'm trying to write a program for validating XHTML 1.1-documents against the XHTML 1.1 DTD (which is actually the same as validating an XML-file) but I always get a "(404) Not found" error. This...
1
by: Craig Beuker | last post by:
Hello, I am experimenting with this XmlValidatingReader and have a question about how it is working (or not working as would be the case) The sample documents and code are included at the end...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
5
by: ameen.abdullah | last post by:
Hi Guys, I have a textbox in windows form that should only accept alphabets, numbers, spaces and underscore. If the textbox contains anyother character it should display a msg at the time of...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
6
by: Richard | last post by:
I'm validating a date and time string which must be EXACTLY of the format yy-mm-dd hh:mm:ss and extracting the six numeric values using sscanf. I'm using the format string "%2u-%2u-%2u...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.