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

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

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

Is this the result you want?

1 Like

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

the only change I made was

this.model.htmllink =;

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

much much appreciated!!!


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 it will return http://

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/

Visit: http://httttps/wwwww/ 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

Then spit out the url,