Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AlphaNumeric Search field

Status
Not open for further replies.

mattys

Programmer
May 1, 2001
35
GB
Hi

I have this bit of ASP script at the top of my page, connected to a search field in a form in the <body> of the page:
------------------------------------------------------------
If Not IsEmpty(Request(&quot;Ref&quot;)) Then
If IsNumeric(Request(&quot;Ref&quot;)) Then
'Add to query
'First item so we don't have to test for WHERE
blnWhere = True 'Set where to true
sql = sql & &quot;WHERE &quot;
sql = sql & &quot;(Ref = &quot; & CStr(CLng(Request(&quot;Ref&quot;))) & &quot;) &quot;
End If
End If
------------------------------------------------------------
I want to change this so I can enter an AlphaNumeric (e.g. P102) search terms.

All help greatly appreciated.

Matt Saunders
 
use regular expressions, there is a good FAQ regarding this...

Known is handfull, Unknown is worldfull
 
Sorry, but I am new to ASP, I have no idea what you mean??
 
vbkris

I have checked out the faq and not found anything of use, is there any way you could advise how to tweak the above code slightly? Is there an alternative expression to Numeric that I could use, something like AlphaNumeric, for example?

Matt
 
there is no function u have to use RegularExpressions
faq333-3645 will give u an idea about it...

Known is handfull, Unknown is worldfull
 
hi, i know how u can do this in JavaScript:
Code:
<script>
function AlphaNumeric()
{
 myval=document.FormName.TextField.value
 if(!myval.match(/^[a-zA-Z0-9]+$/))
 {
  alert(&quot;Please enter only alphanumeric.&quot;)
 }
}
</script>


call this function and see if it works, sorry i dont know how to implement this in ASP...

Known is handfull, Unknown is worldfull
 
Here's the above in VBscript:
Code:
'function to check given string against coded pattern, returns true or false
Function isAlphaNumeric(inStr)
  dim RegX
  set RegX = new RegExp
  RegX.Pattern = &quot;^[a-zA-Z0-9]+$&quot;
  isAlphaNumeric = RegX.test(inStr)
End Function

So you would just:
If IsAlphaNumeric(Request(&quot;Ref&quot;)) Then

Since you are using reg exps it is real easy to make your match more stringent (eg, p 200 or p.2 or p100 but not bbbb1).

Have a look at
Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
ah, i never knew it was so easy...

Known is handfull, Unknown is worldfull
 
Hi, thanks clarkin, still not sure how I would set this out, for example, this is the script I have:

Code:
If Not IsEmpty(Request(&quot;Ref&quot;)) Then
    If IsNumeric(Request(&quot;Ref&quot;)) Then
        'Add to query
        'First item so we don't have to test for WHERE
        blnWhere = True 'Set where to true
        sql = sql & &quot;WHERE &quot;
        sql = sql & &quot;(Ref = &quot; & CStr(CLng(Request(&quot;Ref&quot;))) & &quot;) &quot;
    End If
End If

which is declared at the top of the page before the <html> tag and is referenced by the search form within the <body> tags. Would the example you gave me just replace the above script, for example:

Code:
If IsAlphaNumeric(Request(&quot;Ref&quot;)) Then
Function isAlphaNumeric(inStr)
  dim RegX
  set RegX = new RegExp
  RegX.Pattern = &quot;^[a-zA-Z0-9]+$&quot;
  isAlphaNumeric = RegX.test(inStr)
End Function

Once again, thanks.

Matt
 
Just put the Function .. End Function anywhere on the page, as long as it is within <% and %> and not inside another function. At the very bottom is usually good, after </html>.

Then it is as simple as
[tt]If Not IsEmpty(Request(&quot;Ref&quot;)) Then
If IsAlphaNumeric(Request(&quot;Ref&quot;)) Then
'Add to query
.
.
.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top