用户名字段必须包含仅包含数字的字符 [英] The username field must contain characters only without number

查看:223
本文介绍了用户名字段必须包含仅包含数字的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能这样做..

当我注册用户名时必须只包含字符,



.... ..

i做了这个子并在注册按钮代码中调用它?



我尝试过:



  Sub  TextBox1_TextChanged()
Dim charactersDisallowed As String = abcdefghijklmnpoqrstuvwxyz
Dim theText As String = TxtUser.Text
Dim Letter < span class =code-keyword> As String
' Dim SelectionIndex As Integer = TxtUser.S electionStart
Dim 更改作为 整数

对于 x As 整数 = 0 TxtUser.Text.Length - 1
Letter = TxtUser.Text.Substring(x, 1
如果 charactersDisallowed.Contains(Letter)那么
theText = theText.Replace(Letter, String .Empty)
更改= 1
结束 如果
下一步

TxtUser.Text = theText
' TxtUser.Select(SelectionIndex - Change,0)
结束 Sub

解决方案

嗯。

那段代码呃......不同......

如果你只想让字母,那么为什么要把你想要的字母放在charactersDisallowed字符串中呢? />
而是考虑这个:

  Dim  theText 作为 字符串 = TxtUser.Text 
Dim charsAllowed 作为 字符串 = abcdefghijklmnpoqrstuvwxyz
Dim theNewText As String =
对于 每个 c 作为 字符 theText
如果 charsAllowed.Contains(c)那么
theNewText + = c
结束 如果
下一步


how I can do this ..
when I registering the user name must to contain characters only,

......
i did this sub and call it in the register button code ??

What I have tried:

Sub TextBox1_TextChanged()
        Dim charactersDisallowed As String = "abcdefghijklmnpoqrstuvwxyz"
        Dim theText As String = TxtUser.Text
        Dim Letter As String
        'Dim SelectionIndex As Integer = TxtUser.SelectionStart
        Dim Change As Integer

        For x As Integer = 0 To TxtUser.Text.Length - 1
            Letter = TxtUser.Text.Substring(x, 1)
            If charactersDisallowed.Contains(Letter) Then
                theText = theText.Replace(Letter, String.Empty)
                Change = 1
            End If
        Next

        TxtUser.Text = theText
        'TxtUser.Select(SelectionIndex - Change, 0)
    End Sub

解决方案

Um.
That code is er...different...
If you want to allow letters only, then why put the letters you want in the "charactersDisallowed" string?
Instead consider this:

Dim theText As String = TxtUser.Text
Dim charsAllowed As String = "abcdefghijklmnpoqrstuvwxyz"
Dim theNewText As String = ""
For Each c As Char In theText
    If charsAllowed.Contains(c) Then
        theNewText += c
    End If
Next


这篇关于用户名字段必须包含仅包含数字的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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