I was just wondering if there was a (non-js) solution to prevent "+", "-", "," , "." to be typed in an <input type="number"> in HTML5
            Asked
            
        
        
            Active
            
        
            Viewed 147 times
        
    1 Answers
2
            You can see the solution of other question
<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'>
</input>
I think the only solution is to control what key is pressed and only accent keys from 0 to 9, using their ASCII char code.
I have been researching a way to do only in HTML, but I haven't found anything that works in all browsers.
I don't know if this solution allow the using of backspace, but it would be as easy as include it in the onkeypress event
 
    
    
        Community
        
- 1
- 1
 
    
    
        Albert Lazaro de Lara
        
- 2,540
- 6
- 26
- 41
- 
                    Cheers sir, that's exactly what I needed. The solution was quite obvious, how dumb was I ... – Scipion Mar 20 '17 at 07:20
- 
                    If you like the solution, you can accept it, but I didn't find a solution that no uses Javascript – Albert Lazaro de Lara Mar 20 '17 at 07:22
- 
                    I mean, I didn't want to have js to target elements and apply rules on it, I don't mind having some js directly on my elements that way, I should have been more specific in my question. – Scipion Mar 20 '17 at 07:24
- 
                    So, you should accept the answer clicking on the green tick – Albert Lazaro de Lara Mar 20 '17 at 09:44
- 
                    Indeed, it was just to early to do so before – Scipion Mar 20 '17 at 10:11
