检查输入是否与 STEAM ID 格式匹配
我了解如何匹配它,但我不知道标准,例如,电子邮件匹配器将使用: /^([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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 http://developer.valvesoftware.com/wiki/SteamID#Format 它可能类似于:
^...$
只是为了使确切的字符串必须匹配。STEAM_
是前缀。前缀后面应该有一个从 0 到 5 的数字。
然后是
:
,后跟 0 或 1。然后是另一个
:
,后跟帐号。According to http://developer.valvesoftware.com/wiki/SteamID#Format it might be something along the lines of:
^...$
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.试试这个:
Try this:
我知道这已经过时了,但以下正则表达式对我有用:
^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 ":".[0-1]:
.[0-9]*$
checks that all the following characters are integers between 0 and 9 included.