Zohaib Siddique
Zohaib Siddique

Reputation: 45

Pattern which take input in just positive integer

I want to take input in just positive integer at front end. i also make pattern but it takes input also negative integers but i don't want negative integer in input. kindly help me.

echo "<input type=number pattern=[0-9] value='" . $counter_row['counter_balance'] . "' name=new_cash class=input_panel>";

Upvotes: 0

Views: 180

Answers (3)

Keval Bhatt
Keval Bhatt

Reputation: 6322

Exmaple: http://jsfiddle.net/kevalbhatt18/xya4Lot0/

Use : pattern="\d+"

Now in this example if you use type="number" then at submit time only message very means it will allow only numbe and as you cansee in pattern it will allow only + number

<form>
    <input type="text" pattern="\d+" />
    <input type="submit" />
</form>


Edit:

Example: http://jsfiddle.net/kevalbhatt18/xya4Lot0/1/

<form>
    <input type="number" pattern="\d+" />
    <input type="submit" />
</form>

Upvotes: 0

arkascha
arkascha

Reputation: 42915

That markup looks pretty invalid. You need double quotes around the properties values and that regular expression pattern is only half finished, unclosed. This is probably what you are looking for, more or less:

echo '<input type="number" 
             pattern="[0-9]+"
             value="' . $counter_row['counter_balance'] . '" 
             name="new_cash" 
             class="input_panel">'."\n";

Upvotes: 1

Sunil B N
Sunil B N

Reputation: 4225

Use HTML5 form Validation

<input type="number" min="0">

Upvotes: 1

Related Questions