cancel
Showing results for 
Search instead for 
Did you mean: 

Regex for sap.m.input

former_member793056
Discoverer
0 Kudos

Hi everyone,

I'm trying to implement a m.Input, which only allows inputs in the hh:mm format. I searched the properties but there is no such default option.

TimePicker is no option, because the input should not be limited to 24:00h

So I was wondering if someone has a solution, how I can implement this. I was thinking about some kind of regex implementation.

An additional validation function could be a possible solution, but I find it much cleaner to implement this in a way, that only valid data can be typed in.

Thank you!

Marcel

boghyon
Product and Topic Expert
Product and Topic Expert

Is entering hh:mm > 59 allowed? E.g. 72:99

Accepted Solutions (0)

Answers (2)

Answers (2)

gabmarian
Active Contributor

How about using sap.m.MaskInput ?

<MaskInput mask="HH:Mm" placeholderSymbol="_" placeholder="Enter a time" >
	<rules>
		<MaskInputRule maskFormatSymbol="H" regex="[0-9]"/>
		<MaskInputRule maskFormatSymbol="M" regex="[0-5]"/>
		<MaskInputRule maskFormatSymbol="m" regex="[0-9]"/>
	</rules>
</MaskInput>
venkateswaran_k
Active Contributor
0 Kudos

Hi

Apart from Gábor Márián solution, Additional option may be

var dt = new sap.m.Input({
  change : function() {
    var isValid = /^([0-1]?[0-9]|2[0-4]):([0-5][0-9])(:[0-5][0-9])?$/.test(this.getValue());
    if (isValid) 
    { alert("valid Time format"); }
    else
    { alert("Invalid Time format");}
                      }
});

Regards,

Venkat

venkateswaran_k
Active Contributor
0 Kudos
heideltraud

Is your issue resolved?