Restricting user to input special-characters using Angular [duplicate] - html

This question already has answers here:
Proper way to restrict text input values (e.g. only numbers)
(18 answers)
Closed 2 years ago.
User is allowed to enter all the alphabets and numbers but when the special-characters are entered then it shouldn't be entered in the the text box.
I tried doing this using (ng-pattern-restrict) but it's not working as expected, I think it might be possible that it needs to be imported in
app-module.ts but not working.
HTML FILE

#Shashank has a valid point of view. What you want to do is disable the entry of special characters from the backend, as well as render the field invalid from the frontend. A hacker knowing what they're doing would easily manipulate the HTTP Request itself rather than the field, making it pretty vulnerable.
However, if you insist on your solution, I would recommend using RegEx. This sample expression might come in handy. That way, whenever the input field detects one of these special characters, it would replace that character with a ''

Related

Regular expression UK Phone Number - Optional Digit [duplicate]

This question already has answers here:
Using explicitly numbered repetition instead of question mark, star and plus
(4 answers)
Closed 2 years ago.
I have a pattern that I am using and it does everything I need it to except for it does not allow for an 10 digit phone number and not all UK numbers are 11 digits, for example, 01932 783433 is allowed and valid but 01932 78383 is also valid but not allowed;
Pattern:
^\s*\(?(020[7,8]{1}\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3}\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$
I've tried without success to edit the pattern but each time I make a change and think I'm there the pattern starts allowing non numeric characters like 'ext 456' (extension numbers) at the end which is what I am trying to stop.
Is anyone able to help with a solution to make the 11th digit optional without changing anything else?
The comments of changing {3} to {2,3} resolve the issue I was having and the pointer to regex101.com were very useful in understanding my issue.

How would I parse multiple variables through a dynamic link in html? [duplicate]

This question already has answers here:
Passing multiple variables to another page in url
(8 answers)
Closed 2 years ago.
This may be a relatively simple answer, although I can't seem to find any solution online.
I've been parsing a variable through a dynamic link by using the following line:
a href="play.php?inputType=album"
inputType being the variable I want to parse. Although I also want to parse another variable through the hyperlink although I'm not sure if or how I can add it to the url.
Multiple parameters can be passed through the URL by separating them with multiple "&". Here is an example of the same:
<a href="play.php?inputType=album&name=test">

Store arbitrary characters in Semantic MediaWiki

I'm trying to store some text containing html tags into properties, which doesn't work. I created a form for a property with the data type 'text' and a template. Saving the form writes the text into the template, but it can't get displayed, as it contains illegal characters, as I guess.
What I'm trying to do:
I need a form to enter data, containing html tags and special
characters
I'd like to be able to use a query to find all those pages
and show that text using a template I provide to the ask query.
I also tried to use the free text option, but then I can't retrieve it using the ask query.
What would be the best, or at least a working solution to this?
Thanks a lot
storing text with html tags is a bit tricky in SemanticMediaWiki
The reason is the invention of the StripMarkers UNIQ/QINU by the MediaWiki developers.
When parsing the content of page with html tags in it the parsing is sort of "postponed". This technical detail unfortunately makes it hard for extension developers like the SMW developers to solve the issue of handling such content. Also it makes it hard for lay people to follow the discussion on how to solve the problem
Here are two examples of SMW Issues that are marked as "closed". This state of affairs means that by following the configuration hints in the issue your problem should be solved. If not please ask a question on the SMW issue list or even initiate the reopening of the issues.
https://github.com/SemanticMediaWiki/SemanticMediaWiki/pull/794
https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/3707
On my wiki we ran into this and resolved it by replacing special characters (we had issues with [ ] =, but the same problem happens with to < > tags too) with alternate unicode characters using the regex extension and a template before setting the property with {{#set:}}. If you want to display the formatted text on the wiki directly then call that parameter separately without replacing the unicode characters.
When you want to display the property, you can then run the reverse replacement with regex before displaying your now intact code (using the template result format to allow you to perform the operation on the output of the query).
To switch to special characters you can create this template
{{#regex:{{#regex:{{#regex:{{#regex:{{#regex:{{{1|}}}|/=/|꞊}}|/\[/|[}}|/\]/|]}}|/>/|≽}}|/</|≼}}
And to switch back you can use this as a template
{{#regex:{{#regex:{{#regex:{{#regex:{{#regex:{{{1|}}}|/꞊/|=}}|/[/|[}}|/]/|]}}|/≽/|>}}|/≼/|<}}

Why escape code \n, \r in JSON doesn't work? [duplicate]

This question already has answers here:
Line break in HTML with '\n'
(10 answers)
Closed 5 years ago.
I know I am revisiting an old problem but I hope there are new answers. I am using angular/Modal to display a paragraph from a .json file. I need to insert a newline for each paragraph when displayed in the browser. I have tried \n ,\r, This is a sample of an entry:
"termsAndServiceContent": "1. TERMS OF USE: \n These Terms of Use (Terms) govern your access or use, from within the United States and its territories and possessions ...........\r <br/> By accessing or using the Services, you confirm your agreement to be bound by these Terms........",
I expected to get a new line for the \n and \r but nothing happens. How can I get the browser to recognize the escape characters?
I guess the question is quite similar and I did mentioned that its an old issue. I really didn't see this
https://stackoverflow.com/questions/39325414/line-break-in-html-with-n
question before but I still don't believe the answers address my issue. I am not using plain HTML I am using Angular and my render code looks like this:
<a (click)="showTermAndServicesWindow($event)">{{LOCALIZATION.tos}}</a>
where .tos is my .json file and that's all the HTML I want in the view....also I don't want to do any HTML templating in the .ts modules.
Use the HTML code <br> for new lines, and make sure you use <div [innerHTML]="theHtmlString"></div> to insert it as HTML.

How do I post a sample of PHP code on my webpage? [duplicate]

This question already has answers here:
How do I display PHP code in HTML?
(4 answers)
Closed 8 years ago.
I want to post a sample of some code I've written. I'm aware of the <code></code> tags, but the problem is that the PHP inside will actually get interpreted and executed when the page loads. What is the way around this?
You should be encoding your entities anyway, which will prevent PHP from parsing them.
Instead of <?php, use <php.
See also: What Are The Reserved Characters In (X)HTML?
If you want to display the source of an entire PHP script, you can use the show_source() function. For example,
show_source("sample.php");
If you want to display the code of the current page, you can do something like
show_source(__FILE__);
You can also use hightlight_file() in place of show_source().
If you were looking to display just a random line of code, you can use htmlspecialchars() or htmlentities(). For example,
htmlspecialchars(" <b> This will be a bold text </b> ");
A tip on the aside: Please look around, and google atleast once before asking. :)