|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 ------------------------------------------------------------------------ asimrafi wrote:
Show quote > Hi! i m new to this forum and need some help in ASP On the server side, use VBScript Regular Expressions:> > 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 > ------------------------------------------------------------------------ http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting051099.asp On the client side, use the Javascript version: http://www.regular-expressions.info/javascript.html -- Mike Brind Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general: > On the server side, use VBScript Regular Expressions: Why this serversie preoccupation with vbscript?> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclin > ic/html/scripting051099.asp Jscript regex is cleaner code. Show quote > 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) Evertjan. wrote:
> Mike Brind wrote on 06 mrt 2006 in Ermm... because I don't know Jscript? And I don't think I'm alone in> microsoft.public.inetserver.asp.general: > > > On the server side, use VBScript Regular Expressions: > > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclin > > ic/html/scripting051099.asp > > Why this serversie preoccupation with vbscript? > > Jscript regex is cleaner code. > 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 asimrafi wrote on 06 mrt 2006 in microsoft.public.inetserver.asp.general:
> <% 'vbscript> 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" 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) Evertjan. wrote:
Show quote > asimrafi wrote on 06 mrt 2006 in microsoft.public.inetserver.asp.general: How does the above deal with illegal characters such as ~ \ { } | ?> > > > > 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> > -- Mike Brind Mike Brind wrote on 06 mrt 2006 in
microsoft.public.inetserver.asp.general: Show quote > Illegal in what sense? > 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 ~ \ { } | ? 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:
Show quote > Mike Brind wrote on 06 mrt 2006 in There's an awful lot that's legal in the Netherlands that isn't> 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. ;-) 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.... > I did try it. All it seemed to do was put quotes round strings> 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. > 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.public.inetserver.asp.general: Show quote >> >> <script language='jscript' runat='server'> I took that as having them deleted, as the output was not to be a >> >> // 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 ? true/false, but a corrected string. > Only strings that did not contain those characters (and some others) True, but see my "taking" above.> were allowed - althought the OP didn't say what they wanted to do if > the string contained those characters.... >> Externally to the jscript part, 32-91 -> space-[ >> 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? 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:
Show quote > Mike Brind wrote on 06 mrt 2006 in I goddit. although I'm still not tempted to delve into Jscript> 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 "?". > reference docs ;-) -- Mike Brind Evertjan. wrote:
Show quote > Mike Brind wrote on 06 mrt 2006 in I goddit.... although I'm still not tempted to delve into Jscript> 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 "?". > reference docs ;-) -- Mike Brind |
|||||||||||||||||||||||