Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressoin 1

Status
Not open for further replies.

netquestions

Programmer
Apr 19, 2002
3
0
0
US
hi,

i am designing a form where I accepting a url from the user.
i want to search for :// in the url entered or not. How do I
write the regualar expression for this .

Thanks in advance....
 
var myURLdelimiter = /:\/\//

if (document.myForm.myField.value.indexOf(myDelimiter) != -1)
{
// code for having the delimiter inside the field value.
}

A regular expression approach is great for experience. It's a good idea and I encourage you to use them whenever you can.

Hope this helps. Gary Haran
 
sorry I did one mistake in my code :

if (document.myForm.myField.value.indexOf(myUrlDelimiter) != -1)

also the regular expression is antislash slash ( \ / ) not a huge W as some font settings can show up quite funnily.

Let me know if this helps you Gary Haran
 
hi,

this worked great. i would also like to validate for
:\\, how do i write the regular expression for this ?

thanks for your help ........
 
<script>
var myURLdelimiter = &quot;:\\\\&quot;
var myOtherURLdelimiter = &quot;:\/\/&quot;
var mystr = &quot;:\\\\blablabla&quot;
var myOtherstr = &quot;:\/\/blablabla&quot;
alert('This is mystr: \n' + mystr);
alert('This is myOtherstr: \n' + myOtherstr);

if ((mystr.indexOf(myURLdelimiter) != -1) || (mystr.indexOf(myOtherURLdelimiter) != -1))
{
alert('mystr is ok');
// code for having the delimiter inside the field value.
}

if ((myOtherstr.indexOf(myURLdelimiter) != -1) || (myOtherstr.indexOf(myOtherURLdelimiter) != -1))
{
alert('myOtherstr is ok');
// code for having the delimiter inside the field value.
}

</script>
 
once again if you prefer the usage of regular expression you can use this to check for :\\ or :// in your value :

var myOtherDelimiter = /:\\\\/
var myURLdelimiter = /:\/\//

var myValue = document.myForm.myField.value;

if (myValue.indexOf(myOtherDelimiter) != -1 || myValue.indexOf(myURLdelimiter) != -1)
{
// code for having one of the delimiters inside the field value.
}

I hope this helps. Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top