How do I strip anything that is not numeric...

Results 1 to 3 of 3

Thread: How do I strip anything that is not numeric...

  1. #1
    Join Date
    Dec 1969

    Default How do I strip anything that is not numeric...

    ...from a request.Form?<BR><BR>Let&#039;s say that someone enters "HI" into a field that&#039;s expecting a numeric value. I want to be able to prevent users from doing this.<BR><BR>Does anyone have an ASP or even a JavaScript solution?<BR><BR>Thanks.

  2. #2
    Join Date
    Dec 1969

    Default client or server side?

    If you want to do it client side use javascript. Search google there are plenty of javascript numeric validation scripts out there.

  3. #3
    Join Date
    Dec 1969

    Default Regular Expressions..

    .. are great for just this purpose.<BR><BR>Javascript:<BR>function stripAlphaChars(pstrSource)<BR>{<BR>var m_strOut = new String(pstrSource);<BR> m_strOut = m_strOut.replace(/[^0-9]/g, &#039;&#039;);<BR><BR> return m_sOut;<BR>}<BR><BR>ASP:<BR>Function StripAlphaChars(ByVal pstrSource)<BR>Dim m_strOut<BR> m_strOut = Trim(pstrSource & "")<BR>Dim m_objReg<BR> Set m_objReg = New RegExp<BR><BR> m_objReg.Pattern = "D"<BR> m_objReg.Global = True<BR> m_objReg.IgnoreCase = True<BR> &#039;m_objReg.MultiLine = True<BR><BR> m_strOut = m_objReg.Replace(m_strOut, "")<BR><BR> Set m_objReg = Nothing<BR><BR> StripAlphaChars = m_strOut<BR><BR>End Function<BR><BR>Note: the only reason you got code is because I had it handy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts