How to check the item as this format

to check given Number has numeric and character ‘-’ present in this format
example: 910-123456,
820-123456

Is there is anyway to check,please help me out to solve this

@brindhaS

Str = “820-123456”

Str.Contains("-") AND IsNumeric(Str)

@brindhaS,

You want to check whether the string has numbers and ‘-’ right?

Yes you can do that in two ways…

  1. Loop through all the characters and check whether each character is number or ‘-’

or

  1. String.contains is the predefined class to check it the specific character is present in it

@brindhaS You can use regex expression like below.

value = “820-123456”

System.Text.RegularExpressions.Regex.IsMatch(value.Trim.Replace("-",""),"^[\d]+$")

1 Like