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
------------------------------------------------------------------------ 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
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)
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
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
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)
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
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)
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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.
|
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>
|
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.
|
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.
|
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;
| |
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.
|
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...
|
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...
|
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
|
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.
|
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...
| |
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |