dezkit Posted June 18, 2008 Share Posted June 18, 2008 Is it possible for javascript to see if the text inputted is in the right form? for example i have <input type="text" name="SteamID"> and the form of the input has to be "STEAM_0:x:x" (first x is 0 or 1, second x is any number in infinite amount) Thanks. Quote Link to comment Share on other sites More sharing options...
lemmin Posted June 18, 2008 Share Posted June 18, 2008 You can use regex in javascript: http://www.regular-expressions.info/javascript.html So something like this would probably work: <script language="Javascript"> myregexp = new RegExp("STEAM_[0|1]:[0|1]:[0-9]+"); isSteam = myregexp.exec("STEAM_0:1:3945"); </script> If 'isSteam' is null, then it is in the wrong format. Quote Link to comment Share on other sites More sharing options...
dezkit Posted June 19, 2008 Author Share Posted June 19, 2008 the code doesnt work . im a noob in javascript this is what i have in my page: <script language="Javascript"> myregexp = new RegExp("STEAM_[0|1]:[0|1]:[0-9]+"); isSteam = myregexp.exec("STEAM_0:1:3945"); </script> <form action="confirm.php"> <input type="text" name="SteamID"> <input type="submit" value="submit"> </form> Quote Link to comment Share on other sites More sharing options...
xtopolis Posted June 19, 2008 Share Posted June 19, 2008 Possibly use .match instead of .exec. And then check if isSteam is true or not Quote Link to comment Share on other sites More sharing options...
lemmin Posted June 19, 2008 Share Posted June 19, 2008 That was meant to be an example, not the actual code. <script language="Javascript"> myregexp = new RegExp("STEAM_[0|1]:[0|1]:[0-9]+"); </script> <form id="frm" action="confirm.php"> <input id="tBox" type="Text" name="SteamID"> <button onClick="if(myregexp.exec(tBox.value) == null)alert('Not Steam ID format');else frm.submit();">Submit</button> </form> That should be closer to the way you want to use it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.