Rita Shroff
Rita Shroff

Reputation: 175

Check if String has (9 digits) then

Is there anything like

if abc.text = (some 9 digits/characeters) then

Endif

It should be exact 9 digits/characters then only it goes into the if statement...

Any Idea???

Upvotes: 0

Views: 784

Answers (3)

Farooq Alsaegh
Farooq Alsaegh

Reputation: 161

Module Module1

Sub Main()
    Dim x As String = Console.ReadLine()
    If (x.Length = 9) Then
        Console.WriteLine("We have nine character")
    Else
        Console.WriteLine("we have {0}  character .", x.Length)
    End If
    Console.ReadKey()
End Sub

End Module

Upvotes: 0

Amir
Amir

Reputation: 2098

If you want just to check the lenght us

If abc.text.Lenght = 9 Then

End IF

However if you want to contraint to only number or characters use reqular expression

Dim objRegExp As New System.Text.RegularExpressions.Regex("^[a-zA-Z0-9]{9}$")
If objRegExp.Match(abc).Success

End If

Do not forget to import:

Imports System.Text.RegularExpressions

Upvotes: 1

moffeltje
moffeltje

Reputation: 4658

You can check if the length of your string equals 9:

If abc.Text.Length = 9 Then
    'ToDo
EndIf

Upvotes: 3

Related Questions