JavaScript를 사용하여 텍스트 필드의 공백을 감지하려고합니다. 따라서 텍스트 필드에 공백이있을 때마다 경고가 튀어 나오지만이 코드는 작동하지 않고 두 텍스트 모두에서 작동해야합니다. 전지. 백 엔드 코드는 ASP는 사실에 의해 더욱 모호하게한다 -JavaScript 코드가 작동하지 않습니다.
<!DOCTYPE html>
<html>
<script type="text/javascript">
function detectSpace() {
$returnValue = preg_match('/[^a-z^A-Z^0-9]/', $str, $matches);
if ($returnValue==1)
{
alert("spaces & symbols are not allowed");
}
}
</script>
<body onload="detectSpace()">
<form action="demo_form.asp">
First name: <input type="text" name="FirstName" value=""><br>
Last name: <input type="text" name="LastName" value=""><br>
<input type="submit" value="Submit">
</form>
<p>Click the "Submit" button and the form-data will be sent to a page on the server called "demo_form.asp".</p>
</body>
</html>
JavaScript에는'preg_match' 함수가 없습니다. – jgillich
"$ str"및 "$ matches"란 무엇이며이 변수를 어디에서 정의합니까? –
또한'$ str'은 정의되지 않았습니다. RegExp와 일치해야하는 것이 무엇인지 모르는 함수를 실행 중입니다. PHP와 JS가 얽혀있는 것처럼 보입니다. – Terry