Reputation: 45
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
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
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