I have few input fields.I want to solve a simple formula by given from input. The values comes from the input too.
input1 gives length, input2 gives height, input3 gives width, input4 gives some parameter, and finally input5 is for formula. I want to display the result according to the formula entered.
So far I have successfully done this:plunker.
<div>
<h1>Calculate</h1>
<li>
Length : <input ng-model="l" type="number">
</li>
{{value.length}}
<li>
height : <input ng-model="h" type="number">
</li>
<li>
width : <input ng-model="w" type="number">
</li>
<li>
parameter : <input ng-model="p" type="number">
</li>
<li>
formula : <input ng-model="formula"><br>
formula can be anything;2+l,l+h,2*l*(l+h+w*p)
</li>
<li>
Result :{{$eval(formula) }}
</li>
</div>
I want to validate the formula input so that no other character other than l,h,w,p and numbers and operator can be entered. I might be doing it in wrong way,If so provide some insight or examples.
Thank you.
[0-9lhwp+*/()-]+can be a start.