问题标签 [isalpha]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
129 浏览

python - 如何仅检查字符串的前 5 个字符的 isalpha()?

我想验证一张 PAN 卡,它的前 5 个字符是字母,接下来的 4 个是数字,最后一个字符又是字母。我不能使用 isalnum() 因为我也想检查这个特定的顺序,而不仅仅是验证它是否同时包含数字和字母。

这是我的代码的片段:

这显然会返回错误,因为它是错误的。我怎样才能解决这个问题?

0 投票
2 回答
39 浏览

c - 如何阻止用户插入字符而不是整数

看一下这段代码,它应该以属于结构的三个变量的形式获取用户的出生日期。

如果用户输入字符怎么办?像 1q/02/199i 这样的东西?我想让程序打印一条错误消息,并简单地要求用户再次插入他的出生日期。正如您在代码中看到的那样,我尝试使用 isalpha 函数,但它不起作用,程序崩溃并无限次打印“Invalis input”。如何让用户只插入整数?

0 投票
3 回答
36 浏览

python-3.x - Python isalpha 给出错误的结果

文件只有一行,内容为:“abc”

0 投票
2 回答
54 浏览

python - 有没有办法在 while 循环中简化 isalpha、len 函数?

我是一个非常新的程序员。刚开始使用 Python。本质上,我必须编写一个接受用户名输入的程序,并进行一些验证。用户名必须介于 5-10 个字母字符之间。我正在获取代码来测试字符串的长度,但我没有得到它来测试字母字符。我究竟做错了什么?

0 投票
2 回答
47 浏览

c - How do i have my ppinter point to the new string i created

I need my *str value to be changed to the value of temp so i can use it in another function.

I cannot change the return type, if i could I could just return temp but it has to be void.

0 投票
0 回答
45 浏览

function - 使用 isalpha 检查字符串数组中的特殊字符

所以我试图从一个文件中取出单词并将它们保存到一个动态数组中,然后打印按字母顺序排序的数组以及数组中每个单词的一致性。我在识别特殊字符/数字并将它们从数组中删除时遇到问题。我想使用 isalpha 函数,因为它在分配提示中。当我运行我的代码时,它运行良好,但特殊字符和数字不会从数组中消除。关于如何使用 isalpha 执行此操作的任何想法?

0 投票
1 回答
29 浏览

python - Don't know what to use in this if-statement

So i wanted it to detect if the isr string gonna have a letter for example: "a" or a letter with a number "a8". I tried with the and and orlogical operators, but with the actual code it just gives me "could not convert string to float: 'xxx'" like it kinda just skips the whole if line. When I put the "," instead of and then I put there a "a3" and it says the right thing it should say, but when i put there a normal number that You can actually use in the square rooting it says the thing that it shouldn't.

For and = "a3" the visual studio gonna say "could not convert string to float: 'a3'. For and = "a" it gonna print the right thing "You can't use a letter here.". For and = "4" it gonna print "2.0" as it should.

The one with the , instead of and.

For , = "a3" It prints out the right thing "You can't use a letter here." For , = "a" It prints out the right thing "You can't use a letter here." For , = "4" Should print the 2 but it prints out "You can't use a letter here."

Anyone can help me with it?

0 投票
0 回答
21 浏览

isalpha - 有没有办法检查每个字符是空格还是字母

我正在制作游戏,isalpha() 函数不起作用,因为字母之间有空格。有没有办法查看是否有空格或字母。

0 投票
1 回答
80 浏览

c++ - 我在 C++ 中正确使用 isalpha() 函数吗?

我正在开发一个具有注册系统的程序,您可以在其中注册新成员。

为了提供一些上下文,您注册的名称必须与现有名称不同,只能是一个单词,并且在保存到文件之前变成全部大写。为了避免文件处理中的潜在错误,我只希望用户名是字母,没有数字或特殊字符。

因为我想避免用户可能意外输入的前导和尾随空格,所以我决定将注册的新用户名存储到 char 数组newName中,但我无法弄清楚如何正确地通过 char 数组来检查任何数字或特殊字符,以便我可以要求用户输入正确的用户名。我尝试过使用不同的循环变体和isalpha()函数,但还没有找到任何东西。

这是我的代码的那部分,到目前为止,"sorry, wrong username"无论我输入带有数字/特殊字符还是仅字母的用户名,它都只说明:

0 投票
1 回答
43 浏览

python - 为什么 isalpha() 不能识别字符串中的字母?

我是 python 新手,我在使用 isaplha() 函数时遇到了一些问题。我想检查变量中的某些字符是否是字母。我已经实现了一个遍历所有字符并检查它们是否是字母的 for 循环。

问题是它不区分字母和数字,并且给我'False'作为每个字符的输出(即使它实际上是一个字母!)。我还尝试使用 isdigit() 函数来验证它是否可以区分数字,但在这种情况下,它总是返回“False”。我认为这是一个与变量存储方式有关的问题。我使用的值确实是更大数据框的一部分,但是当我使用 type() 函数时,它告诉我这是类字符串的一部分。我不知道如何解决这个问题。谢谢 !