检查输入是否与 STEAM ID 格式匹配

发布于 2024-11-24 17:15:06 字数 854 浏览 3 评论 0原文

我了解如何匹配它,但我不知道标准,例如,电子邮件匹配器将使用: /^([A-Za-z0-9_\-\.])+\@([A-Za -z0-9_\-\.])+\.([A-Za-z]{2,4})$/ 但我需要知道 steam id 将使用什么。

演示 Steam ID:STEAM_0:1:20206720

有人能给我一个 STEAM ID 的标准吗?

编辑: 我正在使用 pimvdb 提供的正则表达式,但它仍然回复 steam id(STEAM_0:1:20206720) 不正确。

我的代码如下:

function verifySteamID(){
    var elem = document.getElementById('item_name');
    var emailExp = /^STEAM_[0-5]:[01]:\d+$/;
    if(elem.value.match(emailExp)){
        document.getElementById("error").setAttribute("class", "hidden");
        return true;
    }else{
        document.getElementById("error").setAttribute("class", "unhidden");
        elem.focus();
        return false;
    }
    }

调用者:

<input type="submit" value="Donate" id="donatebtn" onclick="return verifySteamID()" />

I understand how to match it but I don't know the criteria for example, Email matcher would use: /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ but I need to know what a steam id would use.

Demo Steam ID: STEAM_0:1:20206720

Could someone give me a criteria for STEAM IDs?

EDIT:
I'm using the regex expression provided by pimvdb, but it still replys that a steam id(STEAM_0:1:20206720) is incorrect.

My code is below:

function verifySteamID(){
    var elem = document.getElementById('item_name');
    var emailExp = /^STEAM_[0-5]:[01]:\d+$/;
    if(elem.value.match(emailExp)){
        document.getElementById("error").setAttribute("class", "hidden");
        return true;
    }else{
        document.getElementById("error").setAttribute("class", "unhidden");
        elem.focus();
        return false;
    }
    }

Which is called by:

<input type="submit" value="Donate" id="donatebtn" onclick="return verifySteamID()" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泛滥成性 2024-12-01 17:15:06

根据 http://developer.valvesoftware.com/wiki/SteamID#Format 它可能类似于:

/^STEAM_[0-5]:[01]:\d+$/

^...$ 只是为了使确切的字符串必须匹配。

STEAM_ 是前缀。

前缀后面应该有一个从 0 到 5 的数字。

然后是 :,后跟 0 或 1。

然后是另一个 :,后跟帐号。

According to http://developer.valvesoftware.com/wiki/SteamID#Format it might be something along the lines of:

/^STEAM_[0-5]:[01]:\d+$/

^...$ is just so that the exact string must match.

STEAM_ is the prefix.

After the prefix there should be one number ranging from 0 to 5.

Then a : followed by either a 0 or 1.

Then another : followed by the account number.

淑女气质 2024-12-01 17:15:06

试试这个:

var input = "STEAM_0:1:20206720"; 
var isValid = /^STEAM_\d:\d:\d+$/.test(input); //true

Try this:

var input = "STEAM_0:1:20206720"; 
var isValid = /^STEAM_\d:\d:\d+$/.test(input); //true
星星的轨迹 2024-12-01 17:15:06

我知道这已经过时了,但以下正则表达式对我有用:
^STEAM_[0-5]:[0-1]:[0-9]*$

工作原理:

  • ^STEAM_ 检查SteamID 开头的“STEAM_”字符串。
  • [0-5]: 查找 0 到 5 之间的整数,后跟“:”。
  • [0-1]: 也是如此。
  • [0-9]*$检查以下所有字符是否为 0 到 9 之间的整数。

I know this is old, but the following RegEx expression works for me:
^STEAM_[0-5]:[0-1]:[0-9]*$

How it works:

  • ^STEAM_ checks for the "STEAM_" string at the beginning of the SteamID.
  • [0-5]: looks for an integer between 0 and 5 included, followed by ":".
  • Same thing for [0-1]:.
  • [0-9]*$checks that all the following characters are integers between 0 and 9 included.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文