<textarea name="test">
http://google.com/
https://google.com/
www.google.com/
[url=http://google.com/]google.com[/url]
text
</textarea>
テキストエリアにURLがあるかどうかを確認する私の現在の試み。
if ($('textarea[name="test"]').val().indexOf('[url') >= 0 ||
$('textarea[name="test"]').val().match(/^http([s]?):\/\/.*/) ||
$('textarea[name="test"]').val().match(/^www.[0-9a-zA-Z',-]./)) {
これは、上記の URL のいずれかをチェックするために完全には機能しないようです。どのように最適化できるのか疑問に思っています。現時点では非常にずさんでハッキングされているように見えますが、誰かが洞察を提供できることを願っています.
テキストエリアから URL を削除する私の現在の試み:
var value = $('textarea[name="test"]').val();
value = value.replace(/\[\/?url([^\]]+)?\]/g, '');
$('textarea[name="test"]').val(value);
現在、次のように出力されます。
<textarea>
http://google.com/
https://google.com/
www.google.com/
google.com
text
</textarea>
出力を次のようにしたい:
<textarea>
text
</textarea>