如何检查字符串是否只包含数字? [英] How to check if a string contains only numbers?

查看:30
本文介绍了如何检查字符串是否只包含数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim number As String = "07747(a)"

If number.... Then

endif

我希望能够检查字符串内部是否只有数字,如果它仅包含数字,则运行 if 语句中的任何内容?我用什么检查来检查字符串是否只包含数字而没有字母 ot () 等..?

I want to be able to check inside the string to see if it only has number, if it does only contain numbers then run whatever is inside the if statment? What check do i use to check if the string only contains numeric and no alpha ot () etc ..?

我要检查的是手机号码,因此应该接受 077 234 211,但不应该接受其他字母

What i am trying to check for is mobile numbers, so 077 234 211 should be accepted, but other alphas should not be

推荐答案

你可以使用像这样的正则表达式

You could use a regular expression like this

If Regex.IsMatch(number, "^[0-9 ]+$") Then

...

End If

这篇关于如何检查字符串是否只包含数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆