Hi,
I've got a Regex for url, which is:
/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/
How can I use it to check an input text in my form, (with an alert pop-up)?
Thanks![]()
Hi,
I've got a Regex for url, which is:
/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/
How can I use it to check an input text in my form, (with an alert pop-up)?
Thanks![]()
I don't think I (fully) understand you, but have a try:
The function fires onblur (meanwhile).Code:<script type="text/javascript"> window.onload=function(){ document.getElementById('test').onblur=function(){ if(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/.test(this.value))alert('Congratulations. That\'s a correct URL.'); else alert('Sorry. That\'s an incorrect URL.'); }} </script> <label for="test">Type a URL here: </label><input type="text" id="test">
Hope that helps.
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
d-machine (08-09-2008)
Thank you!
Is there a simple way to change it to only show the "Sorry. That\'s an incorrect URL." alert? (because I don't need the first alert and I don't know how to edit it..)?
Last edited by d-machine; 08-09-2008 at 10:21 AM.
Replace with this script instead:
Code:<script type="text/javascript"> window.onload=function(){ document.getElementById('test').onblur=function(){ if(!(/^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/.test(this.value)))alert('Sorry. That\'s an incorrect URL.'); }} </script>
Learn how to code at 02geek
The more you learn, the more you'll realize there's much more to learn
Ray.ph!
d-machine (08-09-2008)
Thank you !!
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks