vb.net string contains only 4 digit numbers(or a year) -


how can check if string contains 4 digit numbers ( or year )
tried

 dim rgx new regex("^/d{4}")           dim number string = "0000"     console.writeline(rgx.ismatch(number)) // true     number = "000a"     console.writeline(rgx.ismatch(number)) // false     number = "000"     console.writeline(rgx.ismatch(number)) //false     number = "00000"     console.writeline(rgx.ismatch(number))  // true <<< :( 

this returns false when less 4 or @ characters not @ more 4

thanks!

i wouldn't use regex this. expression deceptively simple (^\d{4}$), until realize need evaluate numeric value determine valid year range... unless want years 0013 or 9015. you're going want value integer in end, anyway. given that, best validation try convert integer right off bat:

dim numbers() string = {"0000", "000a", "000", "00000"} each number string in numbers     dim n integer     if integer.tryparse(number, n) andalso number.length = 4         'it's number. @ other criteria      end if  next  

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -