每一個我有這樣一個形式,我需要提交和替換名稱文本只能是字母,,這是沒有逗號沒有空間或& &% %$$ **,?? ...等。更換並提交文本只有字母不能有空格和逗號期間和其他符號
myform.html
<script>
function fixInput(event) {
name = name.replace(/[^a-z]+/gi, '');
$("input[type=submit]")
}
</script>
<h1>Create a Thing</h1>
<form role="form" action="" method="post" enctype="multipart/form-data">
<input type='hidden' name='csrfmiddlewaretoken' value='CiTMjJgFuTMRatFsQRBUT6z8JuyRhe2g' />
<p><label for="id_name">Name:</label> <input id="id_name" maxlength="255" name="name" type="text" /></p>
<p><label for="id_image">Image:</label> <input id="id_image" name="image" type="file" /></p>
<p><label for="id_description">Description:</label> <textarea cols="40" id="id_description" name="description" rows="10">
</textarea></p>
<input type="submit" value="Submit" />
</form>
,我試圖使用JavaScript和正則表達式來移除和替換文本並提交輸入
名稱
這是
ID =「ID_NAME」
我只是figure ou噸這個js和正則表達式可以做到這一點,,但是我卻不知道如何把它一起在我的形式。我必須更換沒有空格的文本,並且,。* * & ...等等。例如,我不得不讓文本在沒有空間的情況下保持在一起,「這是一個,,,?」 - > 「thisisa」
感謝誰喜歡回答
'str = str.replace (/ [\ s,]/g,'')' – Rajesh
Rajesh給出了答案,儘管你應該看看Mozilla Doc,它在Web開發的每個方面都非常完整,正則表達式也是如此:https:/ /developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp – Cr3aHal0
非常感謝你,,它可以刪除所有的空間和標點符號,但是,我仍然需要統一,如果我在其他語言 –