djbuddhi Posted August 22, 2008 Share Posted August 22, 2008 hey guys need help for this example ; this will be entered in a text area item1 | item2 | item3 | item4 | ...etc i want to check after item1 if the user enter | ,if not message will be alert on keypup or keyenter option how to validate this ??? ??? Quote Link to comment Share on other sites More sharing options...
cleary1981 Posted August 22, 2008 Share Posted August 22, 2008 Can you give an example of what the items are. Do they contain spaces? If so it will be difficult to see where | should be. Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted August 22, 2008 Author Share Posted August 22, 2008 example : clothes | shipping items | goods | like that only clue is that before submitting the form 2 check whether user enters the '|' mark .thats it how to check string by string in a java script ??? ??? Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 22, 2008 Share Posted August 22, 2008 Since an item can have a space in it, there isn't really a way to check if the user is moving on to the next item, so you can't check for the pipe there. You can check at the end before the form is submitted: <html> <head> <script type="text/javascript"> function validate() { var str = document.getElementById("items"); if (str.value.match(/[\|]/g)) str.form.submit(); else alert("no pipe"); } </script> </head> <body> <form> <input id="items" type="text"> <button onclick="validate()">Submit</button> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
djbuddhi Posted August 23, 2008 Author Share Posted August 23, 2008 thanks a lot pal .ur the man ... 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.