Skip to content
Snippets Groups Projects
Commit 3bf340c1 authored by dfurrer's avatar dfurrer
Browse files

OO-1969:changed link from 'callto' to 'tel' , added method to format phonenumber for this link

parent cad5aa9e
No related branches found
No related tags found
No related merge requests found
...@@ -62,14 +62,21 @@ public class PhonePropertyHandler extends Generic127CharTextPropertyHandler { ...@@ -62,14 +62,21 @@ public class PhonePropertyHandler extends Generic127CharTextPropertyHandler {
if (StringHelper.containsNonWhitespace(phonenr)) { if (StringHelper.containsNonWhitespace(phonenr)) {
phonenr = StringHelper.escapeHtml(phonenr); phonenr = StringHelper.escapeHtml(phonenr);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
sb.append("<a href=\"callto:") sb.append("<a href=\"tel:")
.append(phonenr).append("\"><i class='o_icon o_icon_phone'> </i> ") .append(normalizePhonenumber(phonenr)).append("\"><i class='o_icon o_icon_phone'> </i> ")
.append(phonenr).append("</a>"); .append(phonenr).append("</a>");
return sb.toString(); return sb.toString();
} }
return null; return null;
} }
public static String normalizePhonenumber(String phonenr){
phonenr=phonenr.split("[A-Za-z]")[0]; //just take the first sequence before a alphabetic character appears
phonenr=phonenr.replaceAll("\\(.*\\)", ""); // remove brackets and their contents
phonenr=phonenr.replaceAll("[\\s/'\\-\\.,]", ""); //remove bad chars
return phonenr;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem, java.util.Map) * @see org.olat.user.propertyhandlers.Generic127CharTextPropertyHandler#isValid(org.olat.core.gui.components.form.flexible.FormItem, java.util.Map)
*/ */
......
...@@ -78,4 +78,22 @@ public class UserPropertiesTest { ...@@ -78,4 +78,22 @@ public class UserPropertiesTest {
assertFalse(phoneHandler.isValidValue(null, "+41 43 frentix GmbH", error, null)); assertFalse(phoneHandler.isValidValue(null, "+41 43 frentix GmbH", error, null));
} }
@Test
public void testPhonePropertyHandlerHTMLnormalizer() {
// test for valid phone number formats
assertTrue(PhonePropertyHandler.normalizePhonenumber("043 544 90 00").equals("0435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("043/544'90'00").equals("0435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("043-544-90-00").equals("0435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("043.544.90.00").equals("0435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 (0)43 544 90 00").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 x0").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 ext. 0").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 ext0").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 ext 0").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 extension 0").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 Extension 0").equals("+41435449000"));
assertTrue(PhonePropertyHandler.normalizePhonenumber("+41 43 544 90 00 ext. 0").equals("+41435449000"));
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment