Need help in validating users input value(from Screen)

  • Hi guys ,

    Urgently i am in need of validating a input variable comes from screen i.e., i have to throw error or raiserror if the user have does not entered the vale in a particular format

    for example,

    The value should be in this format 'HG#1,MWR#1.5' i.e., the value should start with Alphabets followed by '#' followed by number(1-9) or decimal(1.5 after decimal pot only 5 has to come) followed by ',' then alphabet then '#' then number or decimal ext without any space in between .

    So possible values :

    1.HG#1

    2. HG#1,MWR#1.5

    3. HG#1,MWR#1.5,'somealpabet#number'........

    sorry for my english . Hope every one might understand my request and give a perfect solution.

    so please help me 🙁 thanks in advance

  • Presumably you are using some sort of front-end application (Winform/Web) to get this info from the user. This validation should be done there and not by SQL Server.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (8/2/2013)


    Presumably you are using some sort of front-end application (Winform/Web) to get this info from the user. This validation should be done there and not by SQL Server.

    Thanks a lot for your reply . what ever you are saying is correct , but in our company we put all the validation from SQL Server, using SP(stored procedure). SO that if the requirement is changed we can easily edit the SP. So please help me sir 🙁

  • I see.

    You can probably get quite close through the use of PATINDEX and diligent use of wildcards. Have you tried this?

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (8/2/2013)


    I see.

    You can probably get quite close through the use of PATINDEX and diligent use of wildcards. Have you tried this?

    PATINDEX is just retrieving the index value , but how come this will validate the user input value ? 🙁 could you please show me some related example ?

  • JoNTSQLSrv (8/2/2013)


    Phil Parkin (8/2/2013)


    I see.

    You can probably get quite close through the use of PATINDEX and diligent use of wildcards. Have you tried this?

    PATINDEX is just retrieving the index value , but how come this will validate the user input value ? 🙁 could you please show me some related example ?

    ..And if the desired pattern is not found, it will return zero. That is how you test. You can apply repeated tests to look for different things in your proc, if necessary.

    There are thousands, if not millions, of examples on the Internet if you take the time to search for them.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply