User-707554951 posted
Hi Saipavanchandu,
document.getElementById("id ") return An Element Object
match() is used to String object.
So, you need to get the value of Element Object, Then use match().
https://www.w3schools.com/jsref/met_document_getelementbyid.asp
https://www.w3schools.com/jsref/jsref_match.asp
Besides, you should provide correct id for document.getElementById().
Replace “adderss0” with” txtvalid”;<sub></sub><sup></sup>
Working code as below:
<script type="text/javascript">
function Validate(event) {
var pattern = /^[0-9]{1}[0-9a-zA-Z]+$/;
if (!document.getElementById("txtvalid").value.match(pattern))
{
alert("address must begin with a number");
}
return false;
}
</script>
<asp:TextBox runat="server" ID="txtvalid" onchange ="return Validate(event);"></asp:TextBox>
Output:<sub></sub><sup></sup>
<sub></sub><sup></sup>
Related links about test method and match method in javascript:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
https://websistent.com/javascript-validation-with-regular-expressions/
Best regards
Cathy<sub></sub><sup></sup>