Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
OK, I got this script:
HTML
<html>
<head>
<style type="text/css">
.style1 {
	text-align: center;
}
</style>
</head>

<script language="javascript" type="text/javascript">
    function buttonClick(){
    var url = document.getElementById("inputURL").value + '.html';
    window.location = url;
    }
</script>

<div class="style1">
	<br>
	<br>
	<br>


<input type="text" id="inputURL" name="inputURL" value="" style="width: 225px; height: 37px" ><br>
	<br>
<input type="button" value="click" OnClick="buttonClick()" style="width: 81px; height: 47px"/>

</div>

</html>

Now my question is, I would like to ask the user to enter *#06# then redirect them to 06.html

How do I strip the *#?

What I have tried:

I could not find a solution to solve this problem.
Posted
Updated 26-Jan-22 9:28am
v3

1 solution

Use a regular expression:
Regular expressions - JavaScript | MDN[^]
JavaScript
function buttonClick(){
    const pattern = /^\*\#(\d+)\#$/;
    const value = document.getElementById("inputURL").value;
    if (!pattern.test(value)) {
        alert("Enter a valid URL!");
        return;
    }

    window.location = value.replace(pattern, "$1.html");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900