Announcement

Collapse
No announcement yet.

Check a string meets certain criteria

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Check a string meets certain criteria

    Hi all

    ASP/VB script this question.

    I have a string inputted by the user and I was to check that the result is:

    NumberNumber:NumberNumber

    For example 82:23

    I am able to check it is the correct length but some users are putting in full stops instead of colons.

    Thanks
    Server 2000 MCP
    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

  • #2
    Re: Check a string meets certain criteria

    IIRC there is an "instr" function that tests for the exsitance of a particular substring. Try something like:

    IF INSTR(string, ":") = 0 THEN
    ....error so handle it
    END IF

    Tom
    Tom Jones
    MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
    PhD, MSc, FIAP, MIITT
    IT Trainer / Consultant
    Ossian Ltd
    Scotland

    ** Remember to give credit where credit is due and leave reputation points where appropriate **

    Comment


    • #3
      Re: Check a string meets certain criteria

      Regular expressions are the ticket here.

      Google This

      Here's a working VBS example:

      Option Explicit

      Dim sInput
      Dim objRegExpr

      sInput = InputBox("Enter a string in the format nn:nn")

      Set objRegExpr = New regexp

      objRegExpr.Pattern = "^[0-9]{2}:[0-9]{2}$"

      If objRegExpr.Test(sInput) Then
      MsgBox "Good"
      Else
      MsgBox "Try again"
      End If
      Cheers,

      Rick

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

      Comment


      • #4
        Re: Check a string meets certain criteria

        Thanks Rick, that looks like the badger!

        Reputation left for you.
        Last edited by tonyyeb; 1st December 2006, 10:43.
        Server 2000 MCP
        Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        Comment


        • #5
          Re: Check a string meets certain criteria

          Glad to be of service.

          The rep pts are a welcome bonus.
          Cheers,

          Rick

          ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

          2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

          Comment

          Working...
          X