验证电话#-我在这里遇到错误(电话= CInt(str)),这是什么问题? [英] TO VALIDATE PHONE #- i get an error here ( Phone = CInt(str) ) what is wrong?

查看:95
本文介绍了验证电话#-我在这里遇到错误(电话= CInt(str)),这是什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Private Sub btnPhone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPhone.Click
       Dim Phone As Integer, str As String
       str = txtData.Text
       If IsNumeric(str) = True And str.Length = 10 Then
           Phone = CInt(str)
           lblValidation.Text = "Valid phone number."
       Else
           MsgBox("Invalid number! Just input 10 numbers.", , "Error!")
           txtData.Clear()
           txtData.Focus()
           lblValidation.Text = ""
       End If
   End Sub

推荐答案

每当我看到某个网站要求您不要将任何格式的内容放入电话号码中时,都会感到烦恼,就像很难在代码中将其剥离出来一样...

只需将用户输入的内容取走,然后剔除不是数字的所有内容.然后,您可以根据需要检查结果字符串,最后将结果转换为Integer并将其存储.
It irks the hell out of me every time I see some web site that demands you DON''T put in any formatting into a phone number, like it''s so stinking difficult to strip that out in code...

Simply take whatever the user enters and strip out everything that isn''t a number. Then you can check the resulting string for whatever you want, and finally convert the result into an Integer and store it.


这篇关于验证电话#-我在这里遇到错误(电话= CInt(str)),这是什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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