Check if input has specific text

Hey guys, here is what I got going on. Preformatted text

I have an input that transforms the text in the input and outputs it adding http://

so if a user types google then clicks submit it transforms it to http://google.com.

However if a user types http://google.com then clicks submit it then outputs http://http://google.com.

How can I do a check to see if the input contains http:// so that it ignores my function and it just outputs what the user put. Here is the code on jsfiddle

https://jsfiddle.net/theColombianDev/4dfax8wk/1/

Is this the result you want?

https://jsfiddle.net/8qtx0c6w/

1 Like

hey regchiu you are the best!!! thank you for taking a look i really appreciate it!

the only change I made was

else{
this.model.htmllink = this.model.link;
}

so that if the user inputs http:// it passes.

much much appreciated!!!

@regchiu

one more question how do I check for both http and https? I just realized I left the Https part out when testing. so if I input https://google.com it will return http://https://google.com

Same the approach. But you need to choose whether the output is http or https.

1 Like

Actually it solves nothing.

Enter in : httttps/wwwww/dave.com

Visit: http://httttps/wwwww/dave.com is the result.

Not a valid url.

You need to ensure whats entered is an actual url then decide if it has http / https /www and remove add those to build the url correctly.

enter in -> ftp:// username @hostname/

you get

Hey im here to learn

Visit: http://ftp://username@hostname/

I think your going about it all wrong.

Never trust user input take what they send and say yes or no then modify it to your needs. Simply adding http or not is just simply wrong. UX point of view on a site you let your user get directed to fake address thats 1 lost user.

validate the url input then return the true value or let usre who entered sorry not valid
https://www.regextester.com/96928

Then spit out the url,