473,785 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2512

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.publi c.inetserver.as p.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&"str ingX Ok"
response.write convertMe(a) & "<br>"

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

%>

<script language='jscri pt' 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.publi c.inetserver.as p.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.publi c.inetserver.as p.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(strSearch On,",") then strSearchOn = """" & strSearchOn & """"
Set objRegExpr = new regexp
objRegExpr.Patt ern = "[^\40-\133\135-\172]"
objRegExpr.Glob al = True
objRegExpr.Igno reCase = True
set colmatches = objRegExpr.Exec ute(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.publi c.inetserver.as p.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&"str ingX Ok"
response.write convertMe(a) & "<br>"

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

%>

<script language='jscri pt' 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.publi c.inetserver.as p.general:

Evertjan. wrote:
asimrafi wrote on 06 mrt 2006 in
microsoft.publi c.inetserver.as p.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&"str ingX Ok"
response.write convertMe(a) & "<br>"

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

%>

<script language='jscri pt' 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.publi c.inetserver.as p.general:

Evertjan. wrote:
asimrafi wrote on 06 mrt 2006 in
microsoft.publi c.inetserver.as p.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&"str ingX Ok"
response.write convertMe(a) & "<br>"

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

%>

<script language='jscri pt' 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.publi c.inetserver.as p.general:
>> <script language='jscri pt' 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.publi c.inetserver.as p.general:
>> <script language='jscri pt' 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

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

Similar topics

1
2267
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. http://msdn.microsoft.com/library/en-us/xmlsdk/htm/xsd_devgd_hdi_validate_5zzn.asp This code seems not to be working no matter I do to fix it. I receive the following errors.
1
4337
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" encoding="utf-8"?>| <customers xmlns="http://tempuri.org/customers.xsd"> <Customer ID="1000"> <FirstName>Greg</FirstName>
6
3407
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 accomplish this. I have two strings (C# string type). One of them contains an XML document. The other one contains a schema.
1
2976
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. The problem I am having is that the validation event fires for each node in the xml. It seems to be completely ignoring the schema that I have used. I'm wondering if I need to do something extra to tell the xml which schema to use.
2
2641
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 is the program itself : ******************************************************************** using System; using System.Xml; using System.Xml.Schema;
1
4245
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 of the post. I am using VS.net 2003, .Net 1.1, Win2k Server I have a simple schema and a simple XML document.
2
2128
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 event, I check that the string in the textbox is a file that exists or whether or not the string is blank and display a message box in either case. I also call e.Cancel so that the value will be corrected. However, certain buttons on the form...
5
4817
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 validation.. Is there any funciton in vb.net for this? or any other way?? Waiting for ur replies...
1
3800
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 on the form to reproduce this issue: ------------------------------------ Public Class Form1 Inherits Windows.Forms.Form
6
4509
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 %2u:%2u:%2u" which works, but it allows each numeric field to be either 1 or 2 digits in length. Also the man page for sscanf says that preceeding white space before a numeric is ignored.
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10091
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.