I am trying to validate email and phone number is sapui5. i have done with RegEx. but i want to know sapui5 having any inbuild eMail and Phone number field validator? Without using RegEx?
2 Answers
Update:
Same for sap.ui and sap.m, as the following solution is achieved by data binding validation.
there is no built-in eMail and Phone number field validator. You need to build your own sap.ui.model.SimpleType. Please see the example for Email validation:
here is an example of validation function, attached to event "liveChange" and changing property "ValueState" for sap.m.Input field:
http://jsbin.com/gedap/1/edit?html,css,js,output
<!DOCTYPE html>
<html>
<head>
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<script>
var input = new sap.m.Input({
liveChange : function(oEvent){
var value = parseInt(oEvent.getSource().getProperty('value'));
var valueState = isNaN(value) ? "Error" : value > 3 ? "Error" : "Success";
oEvent.getSource().setValueState(valueState);
}});
input.placeAt('content');
</script>
</head>
<body>
<div id='content'></div>
</body>
</html>
If this is field you are planning to use, then it is easy and fast :)