Chankey Pathak
Chankey Pathak

Reputation: 21676

Applying restrictions on prompt box

I'm taking user input using the prompt box. I want to apply some restrictions on the prompt box so that user can't input anything other than "digits" and the input length should be just one character. Is there any way to do this?

Upvotes: 1

Views: 1239

Answers (2)

cuckovic
cuckovic

Reputation: 2162

You can not change prompt but you can make alert if user enters something you did not want. For example:.

var input = prompt("Enter just one character that is not 'digit'");

if (input.length > 1) {
    alert ("You have entered more than one character.")
    } else if (!isNaN(input)) {    
    alert("Thing you entered is 'digit'.");
} 

Upvotes: 1

VisioN
VisioN

Reputation: 145478

No.

The behaviour of standard dialog boxes, like alert, confirm or prompt, can't be changed. You should implement your own dialogs or use third party implementations, e.g. jQuery UI Dialog.

Upvotes: 3

Related Questions