You need to sign in to do that
Don't have an account?

Validation in lightning component
I've a ui:inputNumber field in lightning component. But this strangely takes input as "+, b, m, k, t". Now I want to restrict it using client side validation.
I've tried NaN and a couple of other methods but still stuck with it. Can anyone help here, as how to write code on controller side?
You can use Regular Expression at client side validation as
I hope this will help you
Regards
Ashif
I want to achieve a bit different solution, I want that user can't enter any value,, i don't want to show any validation error. In VF page, using the reg ex and javascript function i've done it but in lightning component I'm unable to find any thing of that sort.
I just want to restrict user from entering any value other than numbers.
I worked on it
you said 'ui:inputNumber strangely takes input as "+, b, m, k, t'
but this is shortcut functionality
when you type in ui:inputNumber it converts 1k =1000, 1m=1,000,000, 1b=1,000,000,000 , 1t=1,000,000,000,000
I hope this will help you
Regards
Ashif
That's right, it's the functionality I got to know later. But Can I restrict this also?
I've used below function to get value on key press and I'm able to get value to controller but I'm unable to return to the field dynamically as we can do it in VF page.
numcheck : function(component, event, helper)
{
var inp = component.find("departurePremium"); <---finds aura ID
console.log("Inside" +inp);
var Val = inp.getElement().value; <---- gets the value of field dynamicay on each key press
console.log("Input" +Val);
var regexp = /^\d+$/; <---- Reg ex to validate only number
if(regexp.test(Val)){
console.log("Inside if---" +Val); <------Now what would be the code here, to return false or simply don't listen to the event.
val.value = val;
}
},
This is the temporary solution not much good but working as per expectation I hope this will help you Regards
Ashif