• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

Check for values that start with alpha

I have this regex and i swear it was working but now it doesnt. I have order numbers like
WS0000095-1 OR WS0000095 (no dash). I will also have other order numbers like
3199888111 or 99900011-1 (just numbers or numbers with dash)

How can I check if an order number starts with alpha?

declare @orderNum varchar(15)
set @ordernum = 'WS0000095-1'

if (@orderNum LIKE '[A-Za-z][A-Za-z][A-Za-z]%')
    Begin
      select 'test'
    end
0
Camillia
Asked:
Camillia
  • 2
1 Solution
 
strickddCommented:
dbo.RegexMatch( @orderNum, N'^[A-Za-z]' )
0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
Your regex is testing the first 3 characters when it looks like you will only ever have the first 2 characters as alpha.

If you want to just test the first two characters for alpha, change your regex to "[a-zA-Z][a-zA-Z]%"
0
 
CamilliaAuthor Commented:
I can do this, correct?
.... and  @ordernum not LIKE '[a-zA-Z][a-zA-Z]%'

in my sql statement..want to make check if an order number doesnt start with alpha and yes, i just need to check the first 2 digits for alpha
0
 
strickddCommented:
NOT dbo.RegexMatch( @orderNum, N'^[A-Za-z]{2}' )
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now