on 2022 Oct 17 10:54 AM
I have a phone number field in my application and I want to validate it. I am validating it with the regex but it's taking 'e' letter as input .
Can you help me with the regex that doesn't accept 'e'.
Here's what I have tried.
View.xml
<Label text="Phone *" />
<Input Text="Phone" id="iPhone" liveChange="onValidate" maxLength="10"
placeholder="Enter your 10 digit mobile number" enabled="true" type="Number" />
view.controller.js
onValidate: function(oEvent){
var regex1 = "(iFname|iLname|onDetails|iCompany|iAddress|iCity|iProvice|iCountry|iPhone)";
var regex2 = "iZipcode";
var FirstName = ("^[\w'\-,.][^0-9_!¡?÷?¿/\\+=@#$%ˆ&*(){}|~<>;:[\]]{2,}$");
var Phoneregex = ("^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$)")
var Emailregex = new RegExp("^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*@(?:[a-zA-Z-]+\\.)+[a-zA-Z]{2,6}");
var FieldID = oEvent.getParameter("id");
var id = FieldID.split("--")[1];
this.temp = false;
switch (id) {
case "chk0":
if (this.getView().byId(id).getSelected() === true) {
this.getView().byId(id).setValueState("Success");
this.temp = true;
}
break;
}
if (this.getView().byId(id).getValue() !== "" && isNaN(this.getView().byId(id).getValue()) && id.match(regex1)) {
this.getView().byId(id).setValueState("Success");
this.temp = true;
}
else if (id.match("iFname") && this.getView().byId(id).getValue() !== "" && this.getView().byId(id).getValue().match(FirstName))
{
this.temp = true;
this.getView().byId(id).setValueState("Success");
}
else if (id.match("iLname") && this.getView().byId(id).getValue() !== "" && this.getView().byId(id).getValue().match(FirstName))
{
this.temp = true;
this.getView().byId(id).setValueState("Success");
}
else if (this.getView().byId(id).getValue() !== "" && !isNaN(this.getView().byId(id).getValue()) && id.match(regex2)) {
this.getView().byId(id).setValueState("Success");
this.temp = true;
}
else if (id.match("iPhone") && this.getView().byId(id).getValue() !== "" && this.getView().byId(id).getValue().match(Phoneregex))
{
this.temp = true;
this.getView().byId(id).setValueState("Success");
}
else if (id.match("iEmail") && this.getView().byId(id).getValue() !== "" && this.getView().byId(id).getValue().match(Emailregex))
{
this.temp = true;
this.getView().byId(id).setValueState("Success");
}
else {
this.getView().byId(id).setValueState("Error");
this.getView().byId(id).setValueStateText("Please provide valid information " );
sap.m.MessageToast.show("Error !");
this.temp = false;
}
return this.temp;
},
Hi Tanmay,
Try using below code.
<Input id="iPhone" liveChange="onValidate" maxLength="10"
placeholder="Enter your 10 digit mobile number" enabled="true" />
JS:
onValidate: function(oEvent) {
var oSource = oEvent.getSource();
var val = oSource.getValue();
val = val.replace(/[^\d]/g, '');
oSource.setValue(val);
},
Regards,
Manjunatha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.