How to detect if a form action not contain https://?

Like

<form action="">

.prop('action', 'https://www.theaction.com'); // Is to set
.val = "" // If empty

Then something like how to detect if the action property contain https://?

$('form:contains(''https://') or something? But this is for text not for property as I know.

Any idea?

Thanks!

Attributes, like action are accessible in JavaScript:

const form = document.querySelector('form');
console.log(form.action);
1 Like

I understand this get the value. But how check is contain https:// or not or just have there action=“changeme”?

Thanks!

You can do it with regex:

/https?:\/\//.test(form.action);
1 Like

Thank you by the way is not that easy for me to understand.
Please take a look this?

http://jsfiddle.net/zormh4ck/6/

Is always give back true? just for a-z so how check https then? This case is need to be false not? As not just a-z contains?

Thanks!

You have a typo on the following line:

var input = $("register").attr("action");

You are missing a # in front of register.

The reason you /^[a-z]+/.test returns true is because if you assign “https:” to the “action” attribute, the regex matches the “https” because your regex is checking if one or more of the first characters are in the character set a-z.

1 Like