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. Link to comment https://forums.phpfreaks.com/topic/110821-check-for-correct-form/ 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. Link to comment https://forums.phpfreaks.com/topic/110821-check-for-correct-form/#findComment-568619 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> Link to comment https://forums.phpfreaks.com/topic/110821-check-for-correct-form/#findComment-568635 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 Link to comment https://forums.phpfreaks.com/topic/110821-check-for-correct-form/#findComment-568844 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. Link to comment https://forums.phpfreaks.com/topic/110821-check-for-correct-form/#findComment-569197 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.